Can the compiler save me from my own stupidity?

BlitzMax Forums/BlitzMax Programming/Can the compiler save me from my own stupidity?

Robert(Posted 2005) [#1]
One of the problems I often encounter with writing any OOP code is that I write something like:

Global objectVar:TList

Then forget to actually create the object using the New operator (either directly or via another function).

When you later call any list functions, this causes a somewhat bewildering "Unhandled Exception" error, which can be tricky to track down since the error often occurs in a completely different part of the code, or sometimes even a completely different module.

Compilers like GCC / VC++ would print a warning in equivilent code that objectVar has not been initalised.

Does anyone have any ways of dealing with this at the moment? Could any compiler features be implemented to protect me from my forgetfulness?


John Pickford(Posted 2005) [#2]
I suspect it's a matter of waiting for the debugger.


podperson(Posted 2005) [#3]
One simple thing would be for the variable to be initialized to a fixed known bad value and for the error to be flagged appropriately. This was the solution adopted for uninitialized handles by several Mac programming environments.


Chris C(Posted 2005) [#4]
some switches to enable detection of unused variables
would be handy too!

maybe different levels of strict

strict flags

flags could be

unused vars
non matching incbin to incbin::
potential leak warning
case sensitive
etc
etc


John Pickford(Posted 2005) [#5]
I must admit I'd love something that flagged up declared but otherwise unused variables. Over the course of a big project I tend to wind up with quite a few of those.


flying willy(Posted 2005) [#6]
I'd love blitz3d types to be honest. Blitzmax has me confused all the time.


Robert(Posted 2005) [#7]
BlitzMAX types are the same as Blitz3D, just with a few extra features and no global type list.