Well, that’s not how everyone else does it.

12-26-2017

I noticed a little something about the demo code for FASE, when Antonio had defined a function, he had placed at the top of his code a reference to the function instead of the actual function itself.

Me in my extremely finite wisdom, thought, why is he doing it that way, that’s not how everyone else does it…..

Most code that I come across in books and the internet has the following format.

void functionName (int functionFeedVariable)
{
     function code
     .....
     yabbaDabbaDooooo...
}

Main()
{
    amazingStuffInside
}

Whereas Antonio’s code has something like this

void functionName (int functionFeedVariable);

Main()
{
    amazingStuffInside
}

void functionName (int functionFeedVariable)
{
     function code
     .....
     yabbaDabbaDooooo...
}

When I started playing with the engine, I arranged the code to the first style and I was coding along rather happily. The problem starts when I started adding more and more functions to the main code.

Now, forget at the moment about moving code to a .h include file, we are just talking about the main.c code.

What would be the advantage of declaring the function first and place the function below as opposed to placing the actual function above the main code?

As I add more and more functions to the program, I found myself scrolling more and more to the main code past all the functions to get to the main code. In other words, as I add functions, the main code is getting further and further away. Since, after the function is written and is tested I don’t really look at it (unless it gives me trouble) I am just making things a little more difficult finding my place.

So, the other night I sat down and was curled up in reading The C Programming Language by Brian Kernighan and Dennis Ritchie. I noticed something in a sample code they had placed.

They were coding the same way that Antonio’s code was laid out.

Declare the function name first.

Write the main code.

Write the function.

Now for those not aware, Dennis Ritchie is the father of the C language. The first thought that came to mind is “If it’s good enough for Dennis Ritchie, it’s good enough for me!”

It does make good sense to do that for now, it might even help me find stuff a little easier also.

So, the plan is for now, Prototype the functions at the top, and when I then test and finalize the function, move it to the bottom.

Of course, the final solution would be to place all of the functions in a .h and include them, but that is for another time.

Advertisements

Author: andydansby

I'm a hobbyist coder working with the ZX Spectrum. Living in New York state near the Syracuse area. I grew up in Virgina. The first computer my parents bought for me was a Timex Sinclair 2068.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s