Data Management

Poll: Do you use code generation?

Code generation has been getting a lot of attention. Take this poll to let us know whether you use code generation in your programming work.

Many years ago, I discovered that I could use Excel's AutoFill functionality as an ad-hoc code generator when writing tedious SQL statements (I once write a SQL statement with 106 LEFT JOINs in it, thanks to a poor table design). In the past, I've used tools such as Perl to crank out code as well.

Code generation has been getting a lot more attention; in fact, I plan to write a TechRepublic column about it this month. While I question why so many people are writing so much cookie cutter code, it is definitely happening. Are you using any kind of code generation? If so, what?

J.Ja

Disclosure of Justin's industry affiliations: Justin James has a contract with Spiceworks to write product buying guides. He is also under contract to OpenAmplify, which is owned by Hapax, to write a series of blogs, tutorials, and other articles.

---------------------------------------------------------------------------------------

Get weekly development tips in your inbox Keep your developer skills sharp by signing up for TechRepublic's free Web Developer newsletter, delivered each Tuesday. Automatically subscribe today!

About

Justin James is the Lead Architect for Conigent.

20 comments
Osiyo53
Osiyo53

Depends on what sort of coding I'm doing, why, and time constraints. It also depends upon what you mean by code generation. Exact method used, varies widely. In the poll, I voted "Yes, I am using one language to generate another." simply because it is something I sometimes do ... and you didn't provide for a selection which allowed me to state that I also use ad hoc tools AND sometimes tools meant for code generation. In fact, I use all the above from time to time. I program in several different languages as a matter of course. Which language I use depend on the specific project and needs at the time. And, much of the programming I do (most of it) is custom programming for customers. Jobs we've bid on against competitors. With a fixed price and a definite required delivery date. In short, there isn't much room for dinking around or spending any more time than is absolutely necessary to make any particular routine work correctly and adequately. Now move on to the next. As concerns using one language to generate another. Depending on precisely what I'm doing, the kind of project with its requirements, I might use ... or start out using ... something like BCX or Jabaco. BCX is a Basic to C (or C++) translator, Jabaco is a VB6 to Java translator. There are other, proprietary ... and expensive, tools that I use that do essentially the same kind of thing as the two items I mention above but they are tools that it is unlikely any of you have ever heard of and you wouldn't even easily find reference to them on the internet unless you were in the specific business I am as one needs access to web sites/pages that are not open to the general public. So I mention the two, BCX and Jabaco, since its easy for anyone to look up exactly what those two items do. Why do I use em? Simply because Basic is Basic, and I'm a long time Basic coder who has used numerous versions of it. I can knock out the basic structure and fundamentals of a working app to do whatever in Basic faster than I can in, for instance, pure Java starting from scratch. Once I've got the basic app working. Often enough, I'll add refinements, optimize, or whatever in the native final code. i.e. In C, C++, or Java. The intent is to avoid the droll work. For instance, using BCX, I can easily and quickly design a form, add components such as buttons, menus, drop lists, spinners, whatever. Faster and in far fewer lines of typing than doing it in straight C or C++. And in fact will sometimes use a BCX specific form designer which will auto generate BCX code for me from a visual designer where all I need do is draw, drag and drop, edit properties for components using drop down lists, etc. Bang ... in a short time I can have hundreds of lines of C or C++ code generated for me. Most of which consists time consuming, uninteresting and dull code work if done manually in C or C++. Now, often enough the auto code generated is not exactly what I want and I'll go back and do some editing or changes to refine things or add something. But, in the end, it still saves me a LOT of time. And boredom. The same goes with other tools. In my main work I work with a couple of proprietary Visual Programming tools that are quite extensive and complete. One can do some very extensive and complete programs completely in a graphical environment. They're not just forms designers, each has libraries of thousands of function blocks for almost anything one might want to do. Select, drag and drop, draw connections to indicate loops or the passing of information or logic flow from one place to another, etc. Then right click and edit the properties of each function block as needed. But under the hood, the final code generated is C in one instance and Java in the other case. But even those commercial and high priced development apps do have their limitations and quirks. So sometimes it is necessary to go in and make changes or additions the old fashioned, manual way. In other programming languages, for other purposes and projects, I also use ad hoc means for auto code generation. For instance in a couple of them, I have also used Excel, tho differently than your example. Also use a number of single purpose little utilities of my own creation to take the droll work out of at least a part of the coding generation. I don't care for repetitive, dumb typing. If some of the code is of a nature that I can find a way to automate its generation ... I do so. Saves me typing effort and time, reduces the number of typos, and allows me to spend my time and limited brain power on the more important parts of the program.

Tink!
Tink!

I've never used a Code generator. Not even sure if I've even run across one. All my code is from scratch, even repetitive functions. I just wrote a VBscript for a database where I had to repeat the same actions 10 times, each time on a different field. I think a Code Generator sure would have been handy!

kevin.cline
kevin.cline

External code generators are a work-around for inexpressive programming languages. If you are relying on code generators, consider switching to a more powerful language.

meceli
meceli

and code generation is nothing but that.

Jaqui
Jaqui

I only use code generation for basic user interface, like menus, toolbars, status bar. Any other use is adding massive amounts of code, that most likely isn't needed for the application.

filker0
filker0

I've been using some code generators for many years; UI toolkits, YACC/LEX (Bison/FLEX), and other well worn tools come to mind. I've written code generators for specific projects as well, which might fall under the "Ad Hoc" category. As an ancient compiler geek, I might argue that anyone who uses a compiler uses a code generator, and that anyone who uses an object oriented compiled language uses not one, but two code generators. There's also Model Based Development, which is popular in some areas that I've intersected with. I may not be thrilled with the code some of it generates, but it's showing up in more and more places. Code generation is not restriced to any one segment of the industry; Database and User Interface are probably the most common, but I've seen it used in process control as well. What I find most vexing is when I can't generate my own code and must use the higher level code generators even when they don't do exactly what I want them to do.

jck
jck

If I could customize it to be perfect, I'd use it. But, most of the "autofill" functions will not work how I want when I want. So, I just bang away fast enough the popups don't happen and I get it right about 98% of the time.

jkameleon
jkameleon

Generated code is a maintenance nightmare. If program is designed properly, there is no need for code generation, except sometimes Excel. I use it mostly to avoid typos when converting specs to program.

JackOfAllTech
JackOfAllTech

I used Koda Form Designer to create forms for my AutoIt programs and it generates the code from the visual design.

Justin James
Justin James

I have been using ad-hoc tools for a while, but I am just now starting to learn about T4 templates in Visual Studio. What kinds of code generation tools (if any) or techniques are you using? J.Ja

Retired007Geek
Retired007Geek

In my 35 years of experience I've found most code generators are fine if you never have to change the code and have plenty of CPU cycles to burn. Yes, I know most people don't worry much about CPU cycles any more, except when complaining about how slow Windows (pick your version) is...ever think maybe its not all Windows fault? Although, I'm sure Microsoft does the same thing, ever look at the Web pages generated by Office apps? IMHO the platinum apps are hand written by someone who truly understands the language they are using and has a firm grasp of basic programming principles. This is also why the more programmers working on a project the more unexpected errors you encouonter...again think Windows. Please don't bother to reply about the economics of single person projects I'm all too aware of the business imperatives...I'm just stating the optimal case. I've written extensive apps in Excel and do use the Macro Recorder to get a first stab at new operations...but I always redo the code for efficiency and generalization. Ditto Access and Word.

Duke E Love
Duke E Love

As a web developer working on data centric apps I cannot imagine anyone writing apps like that NOT using some sort of code generation. Granted I wrote my own so it does what I want. It writes error free code and takes care of a bulk of the grunt work for CRUD operations like views, forms, Client side error checking for basic data types, the data abstraction layer, controller etc. And with Visio and MSSQL I can go from ERD to working CRUD Admin in about 5 minutes. It will never do 100% of the job but in most cases anywhere from 40-80% of the work is done for me.

hground
hground

I found I was constantly writing the same code for handling object lists (each with different object properties) for many small pieces (apps) of the large project I was working on. At first I wrote a "bat" file to help generate code, but finally wrote a VB .Net app to help generate the List code and individual Item code for the objects. It has saved me a ton of time - instead of re-inventing the wheel or cutting, pasting, and editing the same block of code every time - I type in a few pieces of information and it generates an average of 200-300 lines of code for me. hground

Snak
Snak

I'm no SQL genius. Give me php, C or anything I define as a 'programming' language and I'm fine. Anything that uses such things as LEFT JOIN etc is a pain (to me - it's not where my expertise lies). So if I ODBC my MySQL tables from Access, I can write a query, display the SQL and paste it into my app. Apart from removing the silly square brackets, I find it works really well.

scg8r
scg8r

The independent developers biggest secret. Don't have time to write all of that code. Generate boiler plate code and user interfaces, and then add specific business or techinical logic as needed. Have used for many years since days of MS-DOS programming. It's called Clarion from Soft Velocity, but don't tell anyone.

dtec
dtec

There are times when redundancy is unavoidable. It is those times that I resort to python or excel for generating the code. I don't mind hard work, but I avoid tedious repetition when possible.

grbernard
grbernard

A number of years ago I used "cEnglish", under DOS, which generated C that was in turn compiled I've used "Synon/2e", in the AS/400 environment, which generated RPG that was then compiled. Actually it was more than a code-generator, it's a "development environment" that includes the data-dictionary and "function library". I use "Clarion" in the Windows environment. It generates it's own source language which then compiles. Like Synon, it is a complete environment. I am STRONGLY in favor of these tools, they: - greatly increase my productivity level; - assist in organizing the application, data-library, and functions; - facilitate re-use of tested functions/code; - make ongoing support, modification, and/or extension of the application far easier. I do firmly believe these tools/environments must be "fully adopted", they are NOT "bolt on" pieces. My charter is to produce applications that address my users activities. I use the best tools I can find to provide my user with the best solution at the lowest cost. That's life-time cost, not 1st-time cost.

Tony Hopkinson
Tony Hopkinson

been lumbered with them on occasion (e.g. Datasets in VS), but as a rule I avoid them like the plague. They take some of the donkey work out the job which is fine, but ended up with a shed load of code written by a donkey isn't what I get paid for.

PMPsicle
PMPsicle

And it's not because I'm lazy -- which I am -- it's because my time is better spent using my skills not in producing one more file manipulation. I've been using LANSA for almost 20 years now ... initially on the S/38 then the AS400 and then on the PC. Like SYNON, LANSA is more of a development environment where creating the business rules and design takes precedence over copying code. Unlike SYNON the language is a key element in the tool. One advantage is that I can generate an application with higher quality and more functionality in about half the time of a traditional language/tool. The second is that I can use the same coding skills for coding on the iSeries, PC, Linux/Unix, Palm, and the web. I still need some OS knowledge (for example, I have to build security into a PC or web application -- it's already there in an iSeries app). But in theory, I can simply recompile with a flipped switch to produce a workable (if insecure) application on all five platforms. Unless there's a REALLY good reason, there is no point in coding with a low level language (think Model T vs a Lincoln MkS). Glen Ford, PMP http://www.trainingnow.ca http://www.learningcreators.com/blog

Editor's Picks