I’m speechless

Back last July, I blogged about terrible example code posted by Stephen Ball, an Embarcadero ‘Product Evangelist’. Ultimately, the critique of Ball’s code was really just a lead-off for pointing out how the same anti-pattern used had appeared prominently in the FMX source too. Happily, XE3 RTM saw most of that removed (though not all of it). However, for reasons I don’t understand, Ball has now proudly turned his blog post into a YouTube video:

Honestly, view it and weep. I expect his defence will be ‘but I’m only illustrating class helpers’, but if so, that would be dubious given he’s already been warned the example makes him look foolish [on his original post, the automated pingback from my blog was accepted, but my actual comment – ‘I’ve just posted a critical (but friendly) commentary here’ – never got past the moderation queue. His reply implied he still read it though]. Moreover, it’s perfectly possible to demonstrate class helpers without writing rubbish – check out the relevant page on Lachlan Gemmell’s TIndex for examples. (*)

That said, the class helper anti-example wasn’t the first time Ball had put out poor code – if you want something just as bad, check out his ‘white paper’ on packaging a FMX form into a DLL or dylib, which was also something he originally put out in the XE2 timeframe and has now recently re-promoted. The example used in it is an image file picker, which is fair enough, but here’s how he writes his exports:

  function SelectPicture(AFolder : PChar): PChar; cdecl;
  var
    ResultStr : string;
    Temp: PWideChar;
  begin
    ResultStr := '';
    try
      ResultStr := TfrmImages.SelectPicture(AFolder);
    finally
      Result := StrAlloc(Length(ResultStr));
      Temp := Addr(ResultStr[1]);
      StrCopy(Result,Temp);
    end;
  end;

  procedure DisposePicture(SelectPictureResult : PChar); cdecl;
  begin
    StrDispose(SelectPictureResult);
  end;

If that doesn’t embody the mentality of ‘It compiles, so ship it!’, I don’t know what does.

(*) PS – the David Glassborow articles linked to on the TIndex are now found here and here – I’ve posted the corrections to the TIndex blog, so hopefully the links might even be fixed by the time you read this post.

PPS – eh?

Advertisements

21 thoughts on “I’m speechless

    • During the XE2 cycle, he was the main person putting out example code. I’d never heard of him before, and what he wrote made it plain he had little technical expertise.

  1. I, for one, have no problem with whatever(most videos will bring in more info than just the subject) they show so long as they post HD-FHD videos, but unfortunately, most of the videos lack on all fronts when it comes to quality…

    • Well, I wasn’t complaining about the use of a video, but an apparent inability to care when technical ignorance has been pointed out.

  2. Side note: I’m always pissed off when some “official” delphi spokesmen show code that isn’t properly formatted to the standard delphi style – every day I have to fight with those “I like my code style better”-rookies. I’m really sick of it. Please raise your quality a little bit higher than the delphi-hobbyist level, thank you.

    • Have you seen the FMX sources recently? Because it’s not just ‘spokesmen’ who neither know nor care how to format code idiomatically at EMBT.

    • TBH the official Delphi coding style is pretty bad in many ways, it’s in sore need of modernization.

      Most of the rules don’t improve readability, some actually go against readability good practices and usual typographic conventions. Idiomatically formatted Delphi code looks more like FORTRAN or COBOL than anything modern, while it just doesn’t have to.

      • Speak for yourself! Although, the increase in use of class methods and scoped enumerations certainly doesn’t help.

        • It’s not just myself, it’s the legions of developers that got accustomed to Java, C#, JavaScript, Python etc. which far outnumbers the Delphi and old-style guide Pascal users.
          2 spaces indents? Variables with uppercase? Mixing case in use? Type prefix letter? Some types getting an uppercase and not others? etc. This is just blatantly last century style.

          You may not like the others style, but that’s what has become prevalent, and there are good reasons: coding style shouldn’t be about cosmetics or matching arbitrary standards though about in the era of 4:3 CRTs and fixed-width fonts. Coding style should be about effective, pragmatic readability.

          • 2 spaces indents?
            Sounds good.

            Variables with uppercase?
            Why not? Makes it more readable.

            Mixing case in use?
            Not sure what you mean. Case insensitivity, or simply multi-case identifiers?

            Type prefix letter?
            Tricky one that, but I can live with it, given case insensitivity.

            This is just blatantly last century style.
            What a ridiculous ‘argument’, sorry. Idiomatic C# code doesn’t look like idiomatic Java code, and neither look like idiomatic Objective-C code. Furthermore, the idioms of both Java and Objective-C are as old (older?) than the Delphi idioms.

            coding style shouldn’t be about cosmetics
            WTF? Coding styles should be ugly?

            or matching arbitrary standards
            *Every* standard is ultimately ‘arbitary’ since reality is ultimately concrete.

            though about in the era of 4:3 CRTs and fixed-width fonts
            Er, you code in something that *isn’t* a fixed-width font? Really?

            Coding style should be about effective, pragmatic readability.
            A homily which has no relation to your previous assertions.

          • Replying here since I can’t reply to your post.

            Well, I’m crossing the language boundaries of idiomatic C# and Java regularly (IDE enforced), as well as JS (JSlint enforced), doing a bit of Python as well, and all these four broadly similar in guidelines (indentation, capitalization…), while Borland’s Delphi style isn’t. TBH I’ve long moved my style for Pascal halfway to that of those other languages, and I’m edging ever closer these days, so your comment about all being different doesn’t make much sense to me, sorry.

            As for practical readability, well, it’s also something you have to experience, I cringe every time I look at RTL or VCL source code. It just goes counter to modern conventions in many ways. If you can’t see the issues, well, too bad, but don’t think that because you don’t see them, many won’t see them. It’s definitely part of the problem these days and acts as one more repellent.

          • Well, for me, I find idiomatic C# pleasant to read (Delphi-like even, without the T prefixes) and idomatic Java hard going. As such, I don’t really bracket C# and Java together in terms of style, even though C# as a language might be described as Java ‘done right’.

  3. Yep, this basic videos from Embarcadero ‘Product Evangelist’ is just bad. They think software development is based on drag and drop and that’s it.

    I miss videos and articles from Andreano Lanusse and Nick Hodges, these guys knows how to write technical stuff.

  4. I think official Borland now Embarcadero blog engine blocks all comments that contain url, even the url of your web site that you are prompted to enter when you post comment. And the official guys never care to look into the spam queue.

  5. I read the code and it does seem rather strange. Is it allocating a string in a PChar variable and copying a normal string into it, then disposing of it immediately, instead of just using a compiler-managed string type – is that what you’re speechless about? (It should just be a function returning string?) I admit it does look rather strange. It’s been a while since I’ve used Delphi in this level of detail – do StrAlloc and StrDispose do anything beyond malloc/free, making them unsuitable for using for a plain character pointer-style string too?

    • is that what you’re speechless about?

      No, I was speechless about his re-release (with no amendments) of the class helper example when it had previously been severely criticised.

      It’s been a while since I’ve used Delphi in this level of detail – do StrAlloc and StrDispose do anything beyond malloc/free, making them unsuitable for using for a plain character pointer-style string too?

      The usual style is to ask the caller to allocate a buffer – that way, there’s no need to export a ‘DisposePicture’ routine or the like. However, the try/finally is the real WTF here. My only guess is that someone told him about not letting exceptions escape from a DLL, and he garbled the advice.

  6. In Stephen Ball’s latest blog post, he proclaims that Delphi is so much better for educational use than other languages like Python or “Java Script” because “it has a compiler”! After a lot of thought I think he means “static typing” but doesn’t understand the difference. As written, the blog makes absolutely no sense whatsoever (especially as an interpreter is considered a benefit by educators teaching beginning programming because it allows for immediate feedback). The benefit of static typing for beginners is itself debatable, but the idea that compilers are vital to learn programming is just ridiculous. So it’s not just his code that’s off.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s