I HATE CODING!

Miscellaneous Forums/General Discussion/I HATE CODING!

That's why I have spent 2 weeks writing a Type-based Templated Code Wizard to make my life easier. So far, it has saved me 8 hours of coding. Anyone else write special code generating tools?

So far, it has saved me 8 hours of coding.


Are you counting the time it took you to make?

(wordsperminute * 60) / 1 hour

You probably learnt something anyway, like how to make good types :-)

I have no idea what a type based templated coding wizard is....

short explaination for the laymans?

I dont mind coding as a whole, thats why I enjoy programming, but hard-coding GUI usually drives me nuts though!!! :)

Dabz

today I made a scrollbar :-)

@andy_mc: I originally wrote the program for generating files for my PostNuke CMS based on Database Table Definition Files. With a few tweaks, I turned the utility into a Code Generation tool for my custom Blitz Types (objects).

Type Definition (*.object) File + Template File (*.tpl) --> Code Wizard = Object Class (*.class) Files.

i made coder2d in the code archives under misc. If thats what you mean.

I've done too much to remember - I'm simply the greatest.

Anyone else write special code generating tools?

Yep, it's my day job :-p

You could have done the same with BlitzMax by default (well, when reflection/metadata get here), and had IDE and debugger compatability. Generating object code is not difficult, integrating it into your development environment is where the real hidden cost is.

By the way, code generation in BlitzMax is probably going to end up as a false economy (I do a lot of it, but it's a pain and only a last resort), but you should try out lisp (or scheme), which is designed for it.

PPS - If you're coding at 60 wpm for an hour, then you're writing too much and thinking too little.

How is it possible to generate anything but the most mundane, trivial code?

Genuine question. I've never come across this in 20 odd years of programming.

That's exactly the point of code generation - to fill out mundane code that can't be replaced (directly or nicely) by function calls and/or would be a hassle and error to go through and do manually.

An example of this is my profiling system, which preprocesses BlitzMax files and spits out a version that writes a performance profile to the disk when it ends. The code that it autogenerates is extremely simple - PushFunctionCall() and the start and PopFunctionCall() before each return - but it would be difficult to impossible to maintain this in a project and keep sane.

Another example is C++, which started out life as a preprocessor for C. Virtual methods can be replaced by a function call for sure, but it's not typesafe and looks quite ugly. That's what Frank's code is doing (but he might as well just use BlitzMax instead of messing around with code generators).

Code generation at runtime can also be very useful. You can write a function such as memoize in lisp that will automatically cache the result of a large calculation - basically, the equivilant blitz syntax would be (it can't work for a few reasons but it can in lisp):

Function MyLoadImage:Timage( path$ )

return LoadImage( path )

End Function

Functino MyLoadImageFast = Memoize( myLoadImage )


Which would generate MyLoadImageFast as:

Function MyLoadImageFast:TImage( path$ )

	Global loadedImages:Tmap = new TMap
	
	if ( loadedImage.ValueForKey( path ) )
	
		return TImage( loadedImage.ValueForKey( path ) )
		
	Endif
	
	local im:Timage = loadimage( Path )
	
	loadedImages.Insert( path, im )
	
	Return im
	
End Function


Which will take so many milliseconds on the first call at it loads the image from disk, but subsequent calls trying to load the same image will return the cached version. But the point of code generation is that you can just write the function to generate the cache enabled version of a function once, and from then on you just have to call memoize to automatically generate a cached version of any function, and it'll be bug free.

A good way to think this is to think about functions as a first class data type that you can pass around and manipulate just like integers, strings and objects. So a code generator is a function that operates on a function.

I wrote a program which updated every function/method in the mod directory to state "Entering Function/Method <name>" and "Exiting Function/Method <name>". I used it to find the module path used for Loadimage to DrawImage.
Doing something similar with the profiler I use is a good idea.