Tag: oop

Structuring libraries, basic design tips.

Posted by on August 28, 2009

One of the most important things a programmer has to know and learn is proper code design, structuring of the code, etc. This may not be imperative for you if you’re just starting out, but sooner or later you’ll be able to spot the patterns and realize that your current way of doing things is not optimal but rather cumbersome. This is when you start to separate things into modules and you begin to design your code with more meaning and purpose.

By breaking your code into modules or “classes” you can have a finer granularity of the code itself, you can encapsulate the base code and work on top of it, you can also reuse the code in other projects if you have a good design. An example would be a log library (for logging useful debugging information onto text files) with proper design and care you’ll be able to use the same library in almost all of your projects with little to no modification at all.
More…

Average template

Posted by on August 5, 2009

A tiny template for averaging numbers.
I needed this for a prototype and I didn’t want to “wing it” anymore.

I think there should be a package with similar templates that people could download to enhance the language, I’m just saying… It takes little to come up with this kind of code and in the end it’s always useful to have it around.

You may register it as any numerical type.
Usage example:

You can allocate an instance of the structure with the Create function.
For example, if you registered the template as float, then you may create a dynamic “object” in this way:

Likewise, you should call the Destroy() function to get rid of it.

Trivial but useful. I’m not particularly happy with the naming convention though. But, let’s not forget that this is not an attempt at emulating OOP at all; it’s just a way of giving flexibility to an encapsulated piece of code. For OOP there are proper languages and there is no point whatsoever in trying to emulate it.

Cheers