There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

programmer_humor

This magazine is from a federated server and may be incomplete. Browse more on the original instance.

BlueBockser , in Language

Shouldn’t it be “90+9” for English, though?

lugal , in Language

Don’t look up Danish numbers.

Worst mistake of my life

President_Pyrus ,
@President_Pyrus@feddit.dk avatar

9+(5-1/2)*20

Source: Look at which instance I’m on.

Blamemeta , in I mean it could be right

When the metric is lines of code

mcmoor ,

When the company tries to be cheeky and starts to count characters instead

Johanno ,

Rename c to completelyUnimportantVariableThatISoLongBecauseIGetPaidMore

SpaceNoodle , in I mean it could be right

++x;

damium , (edited )

The underutilized post pre increment operator.

abbadon420 , in I mean it could be right

The third one is just (x=x+1), because the middle bit is just always false and can be ignored.

Hotzilla ,

What if int overflows? Is it still false?

rhpp ,

Still false, thanks to compiler optimizations. Remember that integer overflow is UB. (unless you’re using unsigned int or a programming language which strictly defines integer overflow, possibly as an error)

P.S.: Assuming this is C/C++

chellomere ,

No, because it’s UB, the compiler is free to do whatever, like making demons fly out of your nose

TootSweet , in I mean it could be right

<span style="color:#323232;">for (int y = MIN_INT; y &lt;= MAX_INT; y++) {
</span><span style="color:#323232;">        if (y == x + 1) {
</span><span style="color:#323232;">                x = y;
</span><span style="color:#323232;">        }
</span><span style="color:#323232;">}
</span>

(Not sure there’s a way to prevent Lemmy from escaping my left angle bracket. I definitely didn’t type ampersand-el-tee. You’ll just have to squint and pretend. I’m using the default lemmy-ui frontend.)

xthexder ,
@xthexder@l.sw0.com avatar

y &lt;= MAX_INT will never be false, since the loop will overflow and wrap around to MIN_INT

(You can escape code with backticks, and regular markdown rules)

TootSweet ,

Oh good call! What I was trying to do is more complex than I was thinking.

Hmmmmm.


<span style="color:#323232;">int f = TRUE;
</span><span style="color:#323232;">for (int y = MIN_INT; f || y - 1 &lt; y; y++) {
</span><span style="color:#323232;">  f = FALSE;
</span><span style="color:#323232;">  if (y == x + 1) {
</span><span style="color:#323232;">    x = y;
</span><span style="color:#323232;">  }
</span><span style="color:#323232;">}
</span>

(I should just test my code to make sure it works, but I haven’t. Heh.)

Also, Lemmy escaped your angle bracket too. Back ticks don’t seem to do the trick.


<span style="color:#323232;">Block: &lt;
</span>

Inline: &lt;

Or were you suggesting back ticks for some other purpose? (I did use back ticks in my first post in this thread.)

xthexder ,
@xthexder@l.sw0.com avatar

The backticks worked in the preview, and showed up correctly to start, but there must be a bug in the lemmy ui, since now it’s double-escaped. No idea /shrug

mormegil ,
@mormegil@programming.dev avatar

It will not “overflow”. Signed integer overflow is undefined behavior. The compiler could remove the whole loop or do anything else imaginable (or not).

TootSweet ,

TIL!

I wonder how many languages out there do define what happens on integer overflow.

BatmanAoD ,

Languages with dynamic typing and implicit large-integer types, such as Python and Ruby, generally just convert to that large-integer type.

I figured Java would probably define the behavior in the JVM, but based on a quick web search it sounds like it probably doesn’t by default, but does provide library methods to add or subtract safely.

Rust guarantees a panic by default, but provides library methods for wrapping, saturating, and unchecked (i.e. unsafely opting back in to undefined behavior).

fluxion , in haha patents

It’s amazing how much work goes into cleaning up code before you feel comfortable posting it to a mailing list that you would never even bother doing for internal-only stuff.

nybble41 , in I mean it could be right

I’m fairly certain that last one is UB in C. The result of an assignment operator is not an lvalue, and even if it were it’s UB (at least in C99) to modify the stored value of an object more than once between two adjacent sequence points. It might work in C++, though.

Beanie ,

That was my first thought when trying to figure out what it did

Hephoh2 , in Language

sry but correct french would be:

couleur = “(4*20+10+9)fafalala”;

pennomi , in I am God's greatest programmer

The leash is good unit testing.

gjoel ,

Oh, he’ll just change the unit test if it fails.

Killing_Spark ,

Unit tests are there to get an @ignore annotation!

bappity , in I am God's greatest programmer
@bappity@lemmy.world avatar

me when first starting out at a job commenting everything I can
VS
me a couple years in completely lost because I never updated the comments and now none of them make any sense whatsoever

xmunk ,

Commenting well is a highly advanced skill. I generally prefer no comments on code since it’s less likely to confuse people and I’ll merrily purge auto-doc comments and anything like

// getId() returns an id

That comment has negative value.

kubica ,
@kubica@kbin.social avatar

I can't help it, I always get the mental image of hands clapping sarcastically when I see something like that.

bear ,

I write a lot of fairly simple scripts in Bash and PowerShell that should be easily understood by anybody else with moderate experience in the language, but I leave a lot of obvious comments because my coworkers don’t write any code and are extremely skittish about my automations. I add them basically to quell their fears.

odium ,

Why are coworkers who don’t write any code in the codebase?

bear , (edited )

These are scripts that manage stuff on a few hundred user endpoints and a few servers. They were doing basically everything manually until I got here, and the only way I could get them on board with my slow introduction of automation is to let them see it. I have to ensure things don’t get too long, complex, or hard to explain, or they start getting nervous.

magic_lobster_party ,

Comments should only be used to describe stuff that’s otherwise difficult to convey with code.

dukk ,

Yeah. Most of the time I use comments in my algorithms, as they often use some weird optimized black magic which are difficult to understand without comments.

DoomBot5 ,

Like don’t set this value to the obvious default. Bad stuff happens

xmunk ,

The best explanation I’ve ever heard is:

Comments should state the ‘Why’ never the ‘What’.

hikaru755 ,

There are some cases though where the code is just complicated for reasons outside of your control, in which case “what” comments are good - but they should never be taken at face value, but only used as a first step in understanding the code. There’s a significant risk of the code not actually doing what the comment says.

platypode ,
@platypode@sh.itjust.works avatar

In my experience refactoring lots and lots of crappy code left by devs long gone, a dev who can write useful comments is by and large a dev who can write code clean and simple enough not to need them. If the code doesn’t have informative names and clear separation of concern, chances are a comment won’t help because the dev didn’t really know what they did that worked in the first place.

MagicShel ,

Generally, yes. However I have been known to document exactly why I’m doing something incredibly stupid - because it’s required but a stupid third party library which, despite being awful, is still better than implementing it myself as a refactor.

bappity ,
@bappity@lemmy.world avatar

a dev who can write useful comments is by and large a dev who can write code clean and simple enough not to need them.

my boss is great in this regard and also always has to keep reminding us to write unit tests 😅

MajorHavoc ,

I’ll point to the sign again:

Points to sign

“Comments shouldn’t say ‘what’ the code does, they should say ‘why’ it does it the way it does.”

oce ,
@oce@jlai.lu avatar

I’d rather teach people to comment well through my reviews. Much easier to understand two lines of well written function description in English than 20 lines of code.

Landless2029 ,

Yeah well now we have git copilot where your comments include AI suggestions.

Now I have TONS more comments

southsamurai , in I am God's greatest programmer
@southsamurai@sh.itjust.works avatar

Why is the junior dev tied to the other one’s penis?

ButtCheekOnAStick ,

Because everyone sucks at drawing hands

morrowind ,
@morrowind@lemmy.ml avatar

Bro that’s not where the penis is located on the body

southsamurai ,
@southsamurai@sh.itjust.works avatar

Hey, I don’t body shame

WhiskyTangoFoxtrot ,
ryan , in I am God's greatest programmer

Let him play in the legacy code. You can just hose him off later before letting him back into the office so he doesn't track it everywhere.

ISometimesAdmin ,
@ISometimesAdmin@the.coolest.zone avatar

Unfortunately if you let Junior play in legacy code once, it'll learn some nasty habits and make more of it from scratch, usually when you're trying to sleep.

Hazzia ,

It’s true, spaghettification sauce stains clothes. Best keep Jr out of it entirely.

MagicShel ,

I don’t want that shit all over me though. That’s why I hired junior!

MonkderZweite ,

That’s what the line represents. So they can pull you if you do something nasty.

BaardFigur ,

deleted_by_author

  • Loading...
  • CodeMonkey ,

    If you are creating an alternative implementation and leaving the old one in place, you are not fixing a problem, you are just creating a new one (and a third one because you have duplication of logic).

    Either refactor the old function so that it transparently calls the new logic or delete the old function and replace all the existing usage with usage of the new one. It does not need to happen as a single commit. You can check in the new function, tell everyone to use it, and clean up usage of the old one. If anyone tries to use the old implementation, call them out in a code review.

    If removing or replacing the old implementation is not possible, at least mark it as deprecated so that anyone using it gets a warning.

    BaardFigur , (edited )

    deleted_by_author

  • Loading...
  • magic_lobster_party ,

    I’m sure that ring buffer started out as a “temporary solution”.

    mbp ,
    @mbp@lemmy.sdf.org avatar

    God, I would love that so much

    MamboGator , in I am God's greatest programmer
    @MamboGator@lemmy.world avatar

    The junior doesn’t know that these aren’t unused functions. They’re load bearing functions.

    sbv ,

    Neither does the senior

    Killing_Spark ,

    Anymore

    magic_lobster_party , in I am God's greatest programmer

    There’s also that long time senior dev who’s overly confident in their abilities and force pushes production breaking code directly to master.

    Anticorp ,

    Not for long there isn’t.

    magic_lobster_party ,

    Nah, they’re the one who’s contributing most to the project. Mostly because their code is so garbage no one else can work with it. But that’s not a thing the managers take into account.

    jelloeater85 ,
    @jelloeater85@lemmy.world avatar

    Yeet that shit into main. Who needs unit tests, it works on my computer?

    magic_lobster_party ,

    If it works in my mind it’s ready for production

    jelloeater85 ,
    @jelloeater85@lemmy.world avatar

    Top kek

    wizardbeard ,

    YOLOdev is the best way to dev

    Strawberry ,

    This shit happened the other week for me. Senior dev pushed the shittiest JS code without testing the day of a production install and it caused us to have to roll back the install after it very predictably caused a bunch of crashes for pages on our public site. Worst part is, the entirety of what he wrote could’ve been implemented as a CSS media query

  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • random
  • lifeLocal
  • goranko
  • All magazines