this post was submitted on 13 Oct 2023
805 points (93.5% liked)

Programmer Humor

32572 readers
129 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] pixelscript@lemmy.ml 64 points 1 year ago (2 children)

It's 2023. If you're not using an IDE or a highly extensible text editor with simple static analysis features, I really don't know what to tell you.

[–] GigglyBobble@kbin.social 36 points 1 year ago (2 children)

I had to read it repeatedly and check if it really said "syntax error". What will those people do if they encounter their first race condition?

[–] xmunk@sh.itjust.works 17 points 1 year ago (1 children)

Well, what most of us do... manage to reproduce it by chance one out of twenty attempts and then remove any evidence that you managed to trigger it and mark the ticket "unable to reproduce". Bury the ticket by removing any good tags or keywords and hope it's at least three months until anyone else reports the error so you can repeat the dance.

[–] MajorHavoc@lemmy.world 3 points 1 year ago

I see myself in this comment, and it makes me uncomfortable. Lol.

[–] Arigion@feddit.de 11 points 1 year ago (1 children)

They insert sleep(1) and print statements. No shit. I had to fix this in two projects. One was a complete rewrite.

[–] AVincentInSpace@pawb.social 2 points 1 year ago* (last edited 1 year ago)

Reading this made me nausesous. I feel your pain.

[–] qaz@lemmy.world 2 points 1 year ago* (last edited 1 year ago) (3 children)

Clang won’t tell you if you’re missing a return statement, even with all warnings on and will just let it crash during runtime. Static analysis won’t save you from all stupid mistakes.

[–] pixelscript@lemmy.ml 12 points 1 year ago (2 children)

Static analysis won't save you from all of them, but they will definitely save you from the great majority of the ones ProgrammerHumor seems to get worked up about.

I still see people sharing ancient memes about pouring over code for hours looking for mismatched curly braces, missing semicolons, and greek question marks. These and the bulk of minor syntax problems like them should all be complete non-issues with modern tooling.

[–] TunaCowboy@lemmy.world 5 points 1 year ago (1 children)

clangd should have warned you about this before you even considered compiling.

[–] qaz@lemmy.world 2 points 1 year ago

Thanks, I’ve tried it and it works a lot better than the built in intelli-sense.

[–] sonymegadrive 3 points 1 year ago (1 children)

Clang won’t tell you if you’re missing a return statement.

Is this C++? Have you got some code examples?

I’ve been writing C++ for 20+ years and the last compiler I encountered this with was Borland’s. In the late 90s.

[–] qaz@lemmy.world 1 points 1 year ago* (last edited 1 year ago) (1 children)

It's on the company computer, but I have a backup from earlier today that seems to have the same code.

bool load_metadata() {
    uint8_t marker_field = EEPROM.read(0);
    // Write to ROM if marker has not been set
    if (marker_field != MARKER) {
        metadata = {
            0,
        };
        EEPROM.put(1, metadata);
        EEPROM.update(0, MARKER);
    }
    else {
        EEPROM.get(1, metadata);
    }
}

I have to admit, my experience with C++ is rather limited, last Monday was the first time in my life that I used a C++ compiler. I had some issues getting it to work with Visual Studio, so I ended up using VS Code WSL with clang 😅.

[–] sonymegadrive 2 points 1 year ago (1 children)

Does this compile with -Wall -Werror? (might not be an option if your dependencies’ headers contain warnings)

Looks like it may be embedded code for a SoC or similar. The only things I can think of is that the tool chain you’re using maybe non-standard… or you’re invoking the dreaded Undefined Behaviour somewhere :(

[–] qaz@lemmy.world 1 points 1 year ago* (last edited 1 year ago)

I didn’t use -Werror but no warning about it showed up either. The project uses a semi-custom toolchain for a microcontroller, but I’m not using it to compile this code. I have another file with an entrypoint which tests some classes to be used by the microcontroller. The EEPROM in the code example is actually a macro for a class I’ve written that emulates the EEPROM library by writing and reading to a file on disk.

It’s a bit of a mess but this dual toolchain setup seemed easier than emulating the board and peripherals in it’s entirety. I might have to retry that though using Wokwi.