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
    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

  2. #2
    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;

  3. #3
    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.

  4. #4
    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

  5. #5
    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

  6. #6
    Quote Originally Posted by pstudio View Post
    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.
    I misspelled my statement, I wanted to mean: this is pushing the limits of stupidity. Didn't want to sound rude or politicaly incorrect.

  7. #7
    Ah ok, then I misunderstood you
    Imagine I've written something clever here inspiring you to make something awesome. If that happens give me credits

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
  •