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

Thread: Silly things we used to do?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Question Silly things we used to do?

    Hey guys, since there have been recent topics on things we should do, how about talking about what we have done that we shouldn't have done? What are some of the coding mistakes that you've done in the past that you've learned from of just never got over? What's your worst/best?

    Who is able to make fun of themselves a little?
    Jason McMillen
    Pascal Game Development
    Co-Founder





  2. #2
    Not really a mistake but definitely a silly thing I used to do back in my early days:

    Code:
    var myBool: Boolean;
    ...
    if myBool = true then
      myBool := false
    else
      myBool := true;
    First I figured out that there was no reason to type
    Code:
    if myBool = true then
    when I could just type
    Code:
    if myBool then
    Later I figured out simply to write
    Code:
    myBool := not myBool;
    I comfort myself having seen many beginners write the same kind of code. It's nice to know I'm not the only one
    Imagine I've written something clever here inspiring you to make something awesome. If that happens give me credits

  3. #3
    Code:
    FVar : Booelan;
    
    if FVar = True then
    begin
      ...
    end;
    Actually I like doing that!!! I think it is more readable than:

    Code:
    if FVar then
    begin
      ...
    end;

  4. #4
    Not that i have ever done this, but i can imagine the above code would be about same as this
    Code:
    if (a = b) = True then
    begin
      ...
    end;
    Let's hope the compilers know how to optimize the extra comparison out of executable.

  5. #5
    Quote Originally Posted by User137 View Post
    Not that i have ever done this, but i can imagine the above code would be about same as this
    Code:
    if (a = b) = True then
    begin
      ...
    end;
    Let's hope the compilers know how to optimize the extra comparison out of executable.
    As far as I know, Delphi has a shortcut evaluator for booleans. But this is going to push it to the limits

  6. #6
    Quote Originally Posted by pitfiend View Post
    As far as I know, Delphi has a shortcut evaluator for booleans. But this is going to push it to the limits
    I can't see why a compiler should have a hard time optimizing the code. It seems to me, it would be simple to add a rule saying something like:

    Code:
    if our code says
       boolean = True
    then replace the code with
       boolean
    This should be quite easy when you've made a syntax tree.
    Imagine I've written something clever here inspiring you to make something awesome. If that happens give me credits

  7. #7
    Back in the days when I was making just some trivial applications I have been using forms caption for monitoring progres for some long processing. The reason why I used this approach was the fact that even when you were rapidly changing Forms caption (updating caption for each step) doing this didn't slow down overal procesing much (barly noticable) and the caption did updated even when the rest of the form was unresponsive becouse procesing was done in main thread.
    While this approach works nice on Windows XP and older I strongly disadvise to use this approach on Windows Vista or Windows 7. The reason for this is the fact that Aero desktop don't ofer so quick forms caption drawing as it was on Wondows XP. The reason for this is semitransparent windows that are used in Aero desktop. So changing caption rapidly would lead to considerable slowdowns of you processing, and even worse, it wil cause whole windows GUI to be porly responsive. Having several windows like this can cuse whole windows GUI totaly unresponsive (tried in practice ).
    So instead use normal approaches for monitoring procesing progress like ProgressBars etc. Also try to update these ProgressBArs in certain intervals and not for every step.

  8. #8
    I used to refer to vectors with all its components, without taking advantage of record structures. So something like this was not unusual:
    Code:
    PointInRect(x1, y1, x2, y2, pointX, pointY: single): boolean;
    But you can write it like:
    Code:
    PointInRect(const p: TVector2f; const rect: fRect): boolean;
    It's about consistency in different units. Little by little there became patterns and things "melted" better together.

  9. #9
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25
    Okay fair is fair so here is one of mine.

    I remember when I was first learning about OOP with Object Pascal(we're talking Delphi 3 here) and how you could reference object types in memory by using pointers. Well the beauty of Object Pascal and even Pascal is that you just don't need to use any pointers except in specific cases, well I had them everywhere in my game's code, it was like a nightmare. It was so bad that I even had to check for what kind of object I was referencing.

    The cool trade-off was that I was able to make an array of multiple object types into one. I had to do some crazy stuff to do it, but it was my most experimental project to date, despite the many years ago this was. Needless to say, I'm not a huge pointer fan these days.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  10. #10
    If you need to have multiple objects in same place (array) I suggest to use TList instead. TList is actualy component build around pointer array. Its main advantage over regular arrays is that it already contains necessary methods for item managment (adding items, removing item, moving items, sorting items etc.). If your list contains items of mutiple types (classes) you can always check classname for certain item to determine its type.
    There is also a TObjectList component wich could come verry handy especialy when you use OOP approach in your games (ingame objects are actualy TObject decendants). The main advantage of TObjectList is that it can own its items. What this means? This means that when you remove an object from ObjectList it automaticly cals default destructor method for the object.

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
  •