News for hackers. Stuff that matters.
Re:Poll: What kind of tool do you use to write code? by jacquesm on Saturday December 15, 2012 @03:44PM (#4926285)
I checked 'other' as well because I don't actually write a lot of the code I use software to write it for me. The idea of programs writing other programs has fascinated me pretty much since I started with computers and it has never left me. So if I feel that a piece of code is repetitive I write a chunk of code to write code like that and then re-invoke the generator when I need more code like that. As an example: structures, serialization, de-serialization, validation, allocation, freeing, database storage, variations of the same algorithm in different languages and so on.

To a lisp programmer this would be second nature (they'd wonder why it's so special) but in other languages it can be quite a hassle to keep multiple instances around of similar code.

Code generation is a real booster, the biggest gains I'm getting are 100:1 (a small 10 line definition spitting out a 1000+ lines of code), there is nothing to re-factor just update the generator inputs and hit 'make', old generated code is stripped, new generated code will be inserted into the project so you can inspect it afterwards (and to the compiler it looks just like ordinary human written code). The code generator writes comments as well to clarify the output.

Writing the generators can be quite tricky, you have to think on two levels at once (the code you're writing and the code you want to generate). There are some shortcuts here to make that process easier.

The end result of this process is to have code produced very with - once a single example has been produced and debugged - a much reduced chance of errors.

Re:Poll: What kind of tool do you use to write code? by lowboy on Saturday December 15, 2012 @05:14PM (#4926503)
And what do the interfaces to these programs look like? Are they off the shelf programs or do you have to write (parts of) them yourself?

I'm guessing you still write code.

Re:Poll: What kind of tool do you use to write code? by jacquesm on Saturday December 15, 2012 @07:08PM (#4926781)
> And what do the interfaces to these programs look like?

You get a bunch of readably named functions that you talk to just as if you'd written a library painfully from scratch.

> Are they off the shelf programs or do you have to write (parts of) them yourself?

The interfaces themselves are generated, the code that uses the interfaces is written just like any other program. Unfortunately I can't generate 100% of the code, the business logic bits still need to be written. But even there we're making progress in identifying bits and pieces that are more generic. As more and more code moves to the generated input the whole thing starts to take on the guise of a very high level DSL.

The real knowledge is vested in the generator and how to keep it flexible and still be able to generate code specific to the problem at hand. This can be quite tricky.

> I'm guessing you still write code.

Absolutely, just far less of it than I would have to write otherwise. It's been slow going getting this set up but now that we have it the speed is phenomenal.

Re:Poll: What kind of tool do you use to write code? by zatara on Saturday December 15, 2012 @06:41PM (#4926718)
I am very intrigued by your approach, could you please share more of it or maybe point some books that go deeper on this?
Re:Poll: What kind of tool do you use to write code? by jacquesm on Saturday December 15, 2012 @07:04PM (#4926764)
I can point you in the direction of an open source project that does the same thing in a different way: http://www.python.org/about/success/cog/

That should get you going, be sure to read the introduction.

In the past I've used this trick for many different purposes (for instance, writing driver code for a large variety of graphic cards with various memory lay-outs and port setups, greatly reducing the amount of code to maintain, for performance reasons you don't want that code to be too generic), but lately it has come into its own in a project that I'm working on where the large majority of the code is generated.

Unfortunately I can't share any code (it's written under contract).