"If (YouLoveVCL = true) then TReadThisNow.Create();"

"If (YouLoveVCL = true) then TReadThisNow.Create();"

That was the subject on an EMBT marketing email I just received.

1. You should never compare a boolean with True
2. You should not do work in the constructor
3. This leaks memory (even on NextGen I think?)

Are you spotting any more bad coding practices? :)

Comments

  1. More of a personal preference but I like if statement to be on two lines, the second indented :-)

    ReplyDelete
  2. Nicholas Ring Same, but as this was an email subject I don't argue about formatting :)

    ReplyDelete
  3. Stefan Glienke Is it bad practice to put everything on one line? ;-)

    ReplyDelete
  4. Add the useless parenthesis (both sets), this is not C or Java!

    ReplyDelete
  5. I prefer parenthesis when calling methods, makes it easier to differentiate between methods and properties and if one passes the return value of a method or the method itself.

    ReplyDelete
  6. Nicholas Ring if your code is C/C++, it's ok to put everything in one line, nobody is going to debug/maintain your mess anyway ;-D

    ReplyDelete
  7. Creating a reading situation without executing it.  I do not like the (), and since properties also can have side effects in the getter, I don't use them, even for clarity. I'd also break that line, omit the = true.

    if You.LoveVCL
     then You.ReadThisNow(rmASAP);

    Makes me curious, though - what was the real story?

    ReplyDelete
  8. Promoting a coming webinar, I guess. I agree fewer parenthesis would have been better. Honestly, if it compiles, this is already quite good...

    ReplyDelete
  9. Marco Cantù Is that also the philosophy of FMX? If it compiles, ship it?

    ReplyDelete
  10. Before we go full tilt, I remind and encourage us all that we stay with using the UnitNo5 group for rants and rages, and keep the climate here focused on solutions more than on complaints :)

    ReplyDelete
  11. If this is a message that Embarcadero will focus on VCL again and fix VCL bugs, I am quite happy about that :)

    ReplyDelete
  12. Ondrej Pokorny Yes, more VCL focus, some specific new features, VCL bug fixes... are in the works.

    ReplyDelete
  13. This comparison with TRUE makes me mad every time I see it! Damn, it's a simple Boolean logic... And these useless parentheses - come on, this is not Java. The memory leak is obvious.

    ReplyDelete
  14. Basically: If You.LoveVCL then You.ReadThis(Now);

    Purely as a thought exercise: would this create a memory leak on an ARC-enabled platform? I would expect the object to be created, AddRef'd and immediately Release'd and therefore freed. But I'm not certain about that in this case, since the newly created object is never explicitly assigned to anything.
    (It's a bit of a moot point in this case, since the post is about VCL, which implies no ARC).

    ReplyDelete
  15. Michael Thuma   The semicolon is not really necessary if this statement is the only one in the begin...end block, but I prefer to use them anyway - makes the statement look complete.

    ReplyDelete
  16. Michael Thuma   Now you have an extra closing parenthesis after the semicolon ;-)))))

    ReplyDelete

Post a Comment