Code design

This belates to the Desktop Applications.

I am still adding code to an application that creates html files from data.

I add - earlier today - a new method to extract data from a folder full of files.

I was either lazy or in need to see the feature finished asap, because unlike my previous additions to that project, I do not set html tags into variables (nor Const).

Now, 8 hours laters, I had time to think and was asking myself:
I can add the variables and modify my code accordingly, but why bother ?

What is your opinion ?

1 Like

As developers, I think we all do this. We put in some bit of code or a workaround with every intention to come back later and change or rewrite it, we just want to see it functioning right now. The problem is when we get busy or move on to other things and forget until some point down the road when we have a problem in that code and have no other choice but to do what we should’ve done in the first place. That’s how we end up with bad code that sticks around for years and causes us headaches later.

Generally speaking, nowadays, if I think to myself

I’ll come back later and fix that

I just go ahead and do it because I know it’ll come back to bite me later somehow.

4 Likes

Thank you Anthony.

My code is clear, but I feel using many times

and
in code is not what I have to do / it is better to use variables for that.

After all, aren’t they been created specially for that ? I do not say that in my question to let the answers open.

Note that I am capable of writting bad code too (no later than earlier this week: I’ve made assumptions that worked for the actual problem to solve; I have to go back there and refactor it for all other cases: I “hardcoded” a magazine name where it can be many others (not only that one).
I have to add Controls in the window to set that property and some others.

Have a nice Sunday with your Valentine.

Emile,

If your project is still “in progress,” you’ll likely be in this code again. That would be the time to make it more maintainable.

If your project is more or less done (or you don’t think you’ll need to revisit this piece in the near future), spend 15 minutes a day cleaning it. No need to do it all at once, but a year from now you’ll thank yourself. (I hope I can follow my own advice.)

-Bob

2 Likes

As Xojo is easy to read, I am trying to follow the self-discipline to comment, at least on top of a method, class, event, etc., what I believe this piece should do in the moment of coding it. This has been a lifesaver in the past, especially when I find out, months or years later, that my fantastic code is actually NOT doing what I expected it to do ;-).

The advantage of this “method” is that it is easy and quick to implement.

And even following you, a bad coder can act… and give bad comments.

But you are right. And that is what I have done, in Three Points:

a. Comments
b. Comments
c. Comments

And, in doubts, set some more Comments.

In that case, I even wrote as comments how the Method works (a. do this, b. do that, etc.). Before starting to write the first line of code. Just like if I downloaded my memory to the code page header :wink:

1 Like

Yes, sure :-). My issue with long comments within the code is, that it often contradicts after a while, with what the coding is actually doing (lack of my discipline to update the comments as well). That’s why I am these days mainly concentrating on comments in the “header”.

On a side note: Comments can be funny in professional apps sometimes. When I worked for SAP I bumped once in a while into something like “And this must be a miracle now, I have no idea why this is working but it does. Needs to be reviewed in future” :slight_smile:

SAP is forcing the coder to comment at least the input of routines and the output. That’s what I’m doing often as well, again in the header.

For years now, I’ve always planned on throwing away the first revision of any new code. I’ll create a new module or method, test, fix, test, and then step away for 30 minutes or so. It is the very rare instance where I come back to that code and not see many ways to write the code more efficiently and logically - duplicated properties, or untranslatable string values are almost always waiting to be refactored.

2 Likes

I love this answer !

1 Like

you are so right, most of the Xojo community does not know what a comment is …

I like to segregate tasks - what I do is trim my code down to each task, and work it separately, so I can then add them all in together with bridge code. Modularization allows me to add in features across several apps.

:woman_shrugging: Seems to work fine for me, and seems more efficient.

Hope this helps - it’s like having crib notes, if I explain myself correctly.

3 Likes

One of the strong points of Xojo (and any BASIC-based language, really) is its readability. Some of us do take that for granted as it can be difficult to get lost in code with properly named functions and variables. However, lack of commenting isn’t just limited to within the walls of the Xojo community (or BASIC). I’ve seen truly horrific C++, Javascript, PHP, Obj-C, Perl, and more code that required a decoder ring to follow and had no comments.

3 Likes

The code writer does not have time for comment ? :wink:

No time to comment it, but plenty of time to decipher it when it breaks! :stuck_out_tongue:

3 Likes
Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.