I have this small feeling that we have more control on our application when we manually code it instead of using a code generator. Is it true?
If so then how often should we use a code generator and to what extent?
If not so then can someone guide me to a good place where I can learn about writing code generators?!
And what one would do when decide to open designer of such a form? I would guess that they wouold come to you to punch you
I very often edit them but not remove them, so i guess I am not withbout sin. :p
They're not really generated code, they're code which is manually edited using a graphical IDE. That is, every line in a .designer.cs file is there because you set a property or clicked something in the graphical editor.
What about the performance issues?
Will the code generator not weigh down the application?
Oh and is there any difference a code generator and a template (for an application)? Also is there a relation between the two?
All occasions I've seen and used code generation tools, that's been a build-time issue, not run-time. You run the tool to create code, which is included in the compiling and build of the software. As such, there's no performance penalty when running, although it can complicat the build process.
For instance, Microsoft has a tool that takes an XML file and creates an XML schema from it. This schema can then be run through the same tool which can generate C# classes to represent it. This means you don't have to hand code the classes needed to serialise the XML, but have used a code generation tool. Typically, you'd only do this when there's been a change in the XML schema, not every time you build the system.
I'm not entirely clear what you mean by template here? Do you mean the different application and library types you can pick from when creating a new project in Visual C#? Those templates are effectivel recipes used by the code generation tool to create the project and its initial files.
I very much dislike generated code. If you need so much code to accomplish something that you feel the need to generate it, there is a more fundamental problem that needs addressing, perhaps in the language or choice of technology.
I don't include code which is generated from a non-text editor, like WinForms designer files or WPF/Silverlight XAML. You're still in charge of that, it's just the text editor isn't your usual editing environment. But the abominations that Microsoft create for you when you communicate with a COM or WCF server are fairly clear indications that they need to provide better tools to access those technologies.
But is it not true that developers at entry level have to use a much more hands-on approach, whereas developers at a higher level will have to concentrate on the design of the application from an architectural point of view.
Also as you reach a higher level your responsibilities will increase. Will you use up more of your time by manual coding when you can save your time with a good code generator?
When I first started out as a developer many years ago, I thought that a code generator was a time saver and a great idea. The more experienced I got, the more I realized that code generators end up costing more time than an experienced developer writing it right the first time. Troubleshooting code from a generator is very often far more time consuming.
I have mentored a few developers over the years and I always try to steer them away from using "the easy button" because you don't learn much in development without doing the work yourself. So all in all, I don't like generators at all and I've found that most seasoned developers have tended to come to the same opinion I have of them. Cheers.
What a load of rubbish, you should be using a code generator where it is a valid tool for the job. Coding up the DAL layer is just crazy, coding up the model is just as dumb. Generating code for VM or the VIEW is impossible.
Obviously we are using Silverlight but the code generator we use started life as a VB5 tool in the 90s, it is called ClassBuilder, I pinched it from the lead developer on that project and have rewritten it a dozen times. It does the CRUD stored procedures, the Model (based on a view of the table) and the DAL. Half a dozen click and I have my WCF written.
We tried writing something for the VM and the View but that is where the hand coding is required.
Never underestimate the power of human stupidity