How Code One-liners Can Make Debugging Harder

After reading Norman’s blog , I am curious if the style you code has any performance impact after compiling.

None. The compiler basically breaks down your one-liner into multiple statements anyway. The result is the same.

On a sidenote: I whish Xojo would announce their Blog Posts in the Forum too :wink:

On the other hand, you can add the blog as favourite to your browser and check (daily?) for a new blog yourself. :wink:

It may sound strange but the Xojo Forum is one of two or three Websites (GitHub, …) i visit on a daily or more frequent base. I’ve stopped wasting my time with the search for news. :wink:

Maybe @Dana Brown can arrange it, that each blog post gives a new announcement posting, so the blog entries show up in forum search and in new articles for people.

I don’t mind one liners if it’s a test to exit the function. if j >= 145 then return

Otherwise I agree with Norman that one liners make debugging hell when you run into them.

@Sascha S , @Paul Sondervan , @Christian Schmitz , your contributions have nothing to do with my initial question, so this thread got contaminated. Pity… If @Sascha S had opened another thread asking for announcements of blog-posts it would be clear that one has nothing to do with another.

No reason to be rude, please :slight_smile:
BTW: I contacted Dana right after @Christian Schmitz comment, because i think there’s no need for a new Thread just to ask if it’s possible.

I will not comment off-topic in this Thread anymore. Was not my intension to hijack your Thread. :slight_smile:

It certainly has an impact on my performance; I do the opposite of Norman as it makes code shorter and improves clarity.

I love those simplistic blog posts.

I do both styles. Random code example:

if PBMailbox = nil or PBMails = nil then return

If one of the classes or whatever is Nil I can see it in the debugger. Anther example:

if not checkForSize then Continue

CheckForSize is a method to hide complexity in the main method of the class. For most other use cases I use the multi-line form.

Up till now, me too.

If value1 = True And value2 = True Then result = a * b Else result = a End If

I use to code:

result = If(value1 And value2, a * b, a)

Always bad if you can’t see the intermediate result or the end result.
There may be data type conversion or rounding which can be hard to debug.

[quote=424855:@Joost Rongen]
I use to code:

result = If(value1 And value2, a * b, a)

I still do this all the time. If there’s an issue it can always be rewritten to check it, and that can be undone afterwards.

There’s nothing wrong with one-liners but Normans blog post isn’t wrong either. If you want to put a breakpoint in to test then you have to rewrite it. And that is where things can go wrong because you could easily make a mistake in the rewrite. Anything you touch you have to test and…well…testing.

I’ve done it both ways and it always irritates me when I have to rewrite code just for a breakpoint that may or may not ever be hit.

Let’s call it “coding style” , I can also agree with Bob and Christian while my style is mostly the short notation.
We conclude that is doesn’t effect the compiler and running speed much or not at all.

Its essentially working around a limitation of the ide where you can’t place a break point on the consequent of a condition (the part after the then).

I was thinking about putting in a feature request to have a context menu item added to convert an if then else to/from a single/multi line and back again but I decided to ask for breakpoints on the consequent of a condition instead (<https://xojo.com/issue/54921>).

Greg decided to ask for a shift-enter to convert a one liner to a multi-liner condition (<https://xojo.com/issue/54925>) and its already been implemented by Norman so my request will probably never get implemented as this option, while not perfect, seems like an adequate stop gap solution as a time saver when trying to break point on a single line. I just hope that it also works if you shift-enter after the else, as well as just after the then, but we’ll see how it’s implemented and if it breaks any reformat code script in the process :wink:

As for speed improvements (OP question), I don’t think it does, it’s just a coding style thing, as for how you progress down your method and nesting if’s etc, that’s a different conversation (don’t be put off by the php, its easy to follow what he’s talking about).

It’s implemented for a future Version :wink:

<https://xojo.com/issue/54925>