Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Programming style

  1. #1

    Programming style

    I'm trying to be a bit more structured whilst I'm learning Pascal...I know there are style guides - but don't know if there are programming techniques. I get easy muddled up and have looked at some previous code I have done at it all looks rather messy. The plan I have come up with (don't think it is original) is something along the lines of this;

    program MyBigGame;

    procedure SetUps();
    begin
    { Code here intializes variables etc }
    end;

    procedure GamerInput();
    begin
    { Code here takes instructions from keyboard and mouse }
    end;

    procedure RefreshScreen();
    begin
    { code here does all the foreground and background stuff }
    end;

    { Main }
    BEGIN
    SetUps;
    repeat
    GamerInput;
    Logic;
    RefreshScreen;
    until GameOver=True;
    END.

    Now on top of this have decided that in MyBigGame to label any associated 'sub-procedures' as follows;

    procedure R_Score();
    begin
    { Code to draw the score to the screen }
    end;

    procedure L_Physics();
    begin
    { Code that does the collision detection etc. }
    end;

    So you see the prefix R_ is associated with the "main procedure" RefreshScreen; and L_ is associated with the "main procedure" Logic; ...and so on...

    That way I can clearly see what fits where....

    Now my next question is; is this good practice? How do other people do it? I'm an amateur, and don't work anywhere near the industry...but really want to do this one day as a professional career in some form. My "IDE of choice" at the moment is MIDlet Pascal...decided to focus around that familiarity whilst learning before I move up to a more complex IDE...

    (oops there should be TABS as well in the "Main" so sorry if it all lefthand sided)
    Determined to crack this programming lark...

  2. #2

    Programming style

    If you do game procedurally, people usually separate various logic in separate units..
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  3. #3

    Programming style

    I would use an object-oriented approch. It might be a little more work, but in the end it will make your project very structured and easy-to-maintain.

    Take a look at this page. This is great reference for beginning pascal coders.

    http://www.delphibasics.co.uk/Article.asp?Name=OO

    Good luck!
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  4. #4

    Programming style

    Thanks for your responses....bookmarked that link chronozphere I shall take the bold step into OOP soon....at the moment alot of my code just looks like one heap of mess and was trying to get it in a way when a few months down the line i could decipher it alot easier...I hope...

    Pascal just seems a tidy looking language to learn...I've not download delphi or freepascal...yet...just working with MIDlet Pascal....I hope to post some of my efforts on here one day!
    Determined to crack this programming lark...

  5. #5

    Programming style

    Hi.

    I think everyone develops his owny coding style with the time.. a lot of time
    So if you know some ground rules, it should be ok. You have a base to start.
    The other good way to learn is to read a sources from others. Read sources of freepascal or Delphi, those guys know how to write good code.

    And if after some time you will look at your old code and you think "what a mess, I could do it a lot better now" thats the sign that you have moved forward

    good luck

  6. #6

    Programming style

    Thanks for your support Wodzu...I'm kinda of learning in my own special way if that makes sense...with no preconcieved ideas on how to do things...doing things that way i think may make me a more resourceful, better programmer?

    Theres an awful lot learn, I've got a huge amount of questions that I need to find answers for myself. but there is lots of resources on this website, and you are all so helpful... and of course the internet is there...

    also i'm picking bits up from other languges as well...so piece by piece something is slowly coming together.

    I've got another question...open to anyone; I want to actually move onto Java; ultimately I would like to write mobile apps and games...but, a daft question it may seem; why do a lot of people choose Pascal? <--- thats probably a tough question to ask...but under my own admission as a beginner whilst I'm trying to get to grips with programming, I really don't know what I am talking about...but what are the advantages of Pascal lets say over Java?
    Determined to crack this programming lark...

  7. #7

    Programming style

    Quote Originally Posted by Chobley

    I've got another question...open to anyone; I want to actually move onto Java; ultimately I would like to write mobile apps and games...but, a daft question it may seem; why do a lot of people choose Pascal? <--- thats probably a tough question to ask...but under my own admission as a beginner whilst I'm trying to get to grips with programming, I really don't know what I am talking about...but what are the advantages of Pascal lets say over Java?
    _in general_ Java tries to abstract you too much from the system. This might be different for certain mobile devices with a device specific SDK, but in general it is a bit sluggish.

    Pascal is a very decent language, with some serious speed attached to it, that doesn't shield you from the system. Also it allows to generate binaries (e.g. .exe's on windows) that don't require installation or other files, making it also great for utils and even mid sized apps.

    Personally, one of the gripes with Java is that on one level they pretend it is the same everywhere, and on the other you have to use special editions (J2EE, j2ME), versions, SDKs, widget sets (swt,awt,swing). So first they hook you onto the one to rule all attitude, but when you actually try to do that, you either are stuck with a one size fits all app (that e.g. has a non native feel on windows), or you have to differentiate again, negating the use of using Java in the first place.

    That combined with the more difficult interaction with other software (be it OS or other apps not specifically written to communicate with Java) is why I only do it when I can't avoid it. (and if Windows is a major factor, that is almost never, beter go with .NET then)

    For mobile games it is different, because sometimes you can't use native code (due to native bins not being allowed), but this is not a technical reason, but marketing.

    But even then, even Java is not always as free either, so be careful, some Java devices will only run java apps when properly signed, and you have to register and pay for that. (e.g. carrier locked phones). Be sure to check your targets first if you can actually run custom Java code on them.

  8. #8

    Programming style

    Thank you for that insight...all I have done is stuck around mobile phones, written a few test pieces of code and now applying what I have learnt into making a game.

    I like the idea that Pascal as you said can do applications...that is something that I'd like to step into;

    I see there is going to be a competition on here soon; so that would be a good incentive to download the Pascal desktop stuff and get cracking on that...time to move on a bit;

    I'm getting more towards "I know a little bit about somethings" and where if I don't know something now; at least I know where to look in manuals to find out...I'm taking things one step at a time with familiarity, because very quickly it can blow your mind if you are a beginner - and then you just give up!

    I hope to post a mobile Pascal game on here soon, it isn't great but the basis of it is stuff that I have learnt, my first attempt at structuring the code better, however still procedural based...for now...it should auto size as well for any Java enabled phone.
    Determined to crack this programming lark...

  9. #9

    Programming style

    Quote Originally Posted by Chobley
    I hope to post a mobile Pascal game on here soon, it isn't great but the basis of it is stuff that I have learnt, my first attempt at structuring the code better, however still procedural based...for now...it should auto size as well for any Java enabled phone.
    I really would like to see it! I made one simple game in Java for mobile few years ago but making it workable on different machines was awfull.

  10. #10

    Programming style

    Wodzu...yeah I can do that; I don't think you can attach files here, i mean the .jar file.

    Or can you?

    It is quite simple I've tested it on my p990i (yes...i know...should not have bought one) and an old antiquated 128 x128 MIDP 1.0 device.

    I don't have a website to upload it to either...yet...

    It's a colour game, with levels and records also the High score; graphics based on not image files but by using drawing commands...

    Now I can post the code on here for all to see or did you just want to see the code in how I did it?

    If I do it that way; then you need to download MIDlet Pascal for which is was written in....you can go to www.midletpascal.com to get this...

    (If you know MIDlet Pascal then you may know that their website has been inactive...well now it isn't)
    Determined to crack this programming lark...

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •