programmer_humor

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

Truck_kun, in It's that time of the year again!

That SELECT and WHERE are all caps, but from is not is bugging me.

I don’t care if you choose to uppercase keywords or lowercase, but consistency please.

Also, great, love it.

cupcakezealot,
@cupcakezealot@lemmy.blahaj.zone avatar

it also implies that naughty or nice is an either or thing and not a weighted thing from an incidents table. the good place lied to us.

ursakhiin,

It could be a materialized view that is generated off of a weighting where you are nice until you have a certain number of incidents.

rikudou, (edited ) in isEven API
@rikudou@lemmings.world avatar

If anyone wants a more efficient local version for php:


<span style="color:#323232;">function isEven(int $number): bool
</span><span style="color:#323232;">{
</span><span style="color:#323232;">    ${1} = false;
</span><span style="color:#323232;">    ${2} = true;
</span><span style="color:#323232;">
</span><span style="color:#323232;">    while ($number > 2) {
</span><span style="color:#323232;">        $number -= 2;
</span><span style="color:#323232;">    }
</span><span style="color:#323232;">
</span><span style="color:#323232;">    return $$number;
</span><span style="color:#323232;">}
</span>

Edit: Now with support for large numbers!


<span style="color:#323232;">function isEven(int|string $number): bool
</span><span style="color:#323232;">{
</span><span style="color:#323232;">    ${1} = false;
</span><span style="color:#323232;">    ${2} = true;
</span><span style="color:#323232;">
</span><span style="color:#323232;">    while (bccomp($number, 2) === 1) {
</span><span style="color:#323232;">        $number = bcsub($number, 2);
</span><span style="color:#323232;">    }
</span><span style="color:#323232;">
</span><span style="color:#323232;">    $number = (int) $number;
</span><span style="color:#323232;">    return $$number;
</span><span style="color:#323232;">}
</span>

Edit 2: someone asked for an ad-supported version, here you go!


<span style="color:#323232;">function isEven(int|string $number): bool
</span><span style="color:#323232;">{
</span><span style="color:#323232;">    ${1} = false;
</span><span style="color:#323232;">    ${2} = true;
</span><span style="color:#323232;">
</span><span style="color:#323232;">    while (bccomp($number, 2) === 1) {
</span><span style="color:#323232;">        error_log('Buy isEvenCoin, the hottest new cryptocurrency!');
</span><span style="color:#323232;">        $number = bcsub($number, 2);
</span><span style="color:#323232;">    }
</span><span style="color:#323232;">
</span><span style="color:#323232;">    $number = (int) $number;
</span><span style="color:#323232;">    return $$number;
</span><span style="color:#323232;">}
</span>

Side note, no more suggestions please, this is getting quite long.

shotgun_crab,

Comment edits are the best version control system

rikudou,
@rikudou@lemmings.world avatar

I agree! Added new commit to my comment.

idunnololz,
@idunnololz@lemmy.world avatar

This looks pretty inefficient. You should manually unroll that loop to improve performance.

xmunk, (edited )

I fucking love that you managed to use var-vars in a completely key and necessary manner.

But please do adhere to the API TOS and throw in an error_log(‘Buy isEvenCoin, the hottest new cryptocurrency!’);

rekabis, (edited ) in Programmer tries to explain binary search to the police

“This argument didn’t go down well.”

🤣🤣🤣 LMAO

What an awesome punchline, should have been on its own line for more impact.

takeda, in 10 months later bill revisits his spaghetti code. forgets absolutely everything and refuses to elaborate. this wouldn't have happened if Bill forgot to comment on his code

I’m Bill I don’t comment my code (except complex parts), instead I try to make code clear, including using proper variable and function names and try to keep functions short. I don’t think I ever got lost in my own code in my 20+ years of experience. Even got complements about it.

The programming language is meant for humans to read/write, if you need to put comments to understand your code then your code sucks.

robdor,

I think that makes you Phil, not Bill. Thanks for the good work you do Phil.

krellor,

When writing basic business code, structuring the code well and having good naming standards means you shouldn't need a ton of comments, but you should still have some. Plus, using structured function content blocks gives you intellisense in some languages and IDEs, which is important for code reuse in teams.

However, when I was doing scientific programming I'd have comments for almost every line at times where I put the mathematical formula and operations the line represents. Implementing a convolution neutral network with parameters to dynamically scale the layers or MPI stochastic simulations is much different than writing CRUD functions or basic business logic.

ILikeBoobies,

Comments are there to make your ctrl + f’s faster

suodrazah,

Use comments to describe the philisophy of the code, the why. And any non obvious extended relationships. Risk. Etc.

Comments on function are typically a waste of space.

NuXCOM_90Percent,

Commenting is an art. Too much and it is outright misleading after the first hotfix. Too little and only the original developer can maintain it

But uncommented code is a dick move. And, more importantly, it means you can’t punt bug fixes to the intern

Anders429, in the myth of type safety

I’ve seen this same thing happen with Python’s type hints. Turns out giving an “escape hatch” type for devs who have no clue what the type actually is leads to a lot of useless type hints.

vzq,

/me laughs in void*

magic_lobster_party,

Laughs in Object

RandomDevOpsDude,

Laughs in object

Knusper,

Yeah, it’s especially bad, when a library doesn’t provide type hints itself. It can be comically difficult to find out what the return type of a function is, because every if-else-branch might have a different return value, so you may need to read the function body in full to figure out what the type might be.

Add to that, that lots of the tooling around type hints isn’t as fleshed out / useful as it is in fully typed languages and I can definitely understand why someone might not immediately feel like it’s a valuable use of their time.

AeonFelis, in Infinite Loop

After so many years in this company, lots of the unmaintainable code I have to deal with is either my own fault, or the fault of someone I used to work with but and now they left and I’m the one who has to apologize for their code.

If I move to a different company, 100% of the unmaintainable code I’ll have to deal with there will be someone else’s fault.

owen,

In the industry we call this responsibility load balancing

SpaceCowboy,
@SpaceCowboy@lemmy.ca avatar

And managers don’t like it when you explain that the code is a unmanageable mess because they put a deadline on every goddamn thing and never pay off technical debt.

At a new place you can honestly say “the code is kinda a mess, it needs a bunch of work” and the manager can just assume it was because the last guy didn’t know what he was doing and not because of their own shitty management.

soggy_kitty,

To be honest, sometimes shit code is 100% the Devs fault. I’ve witnessed it happen with other teams in my own company.

Let’s just say it was unavoidable to report it

SpaceCowboy,
@SpaceCowboy@lemmy.ca avatar

Management could implement a code review process to avoid this.

Software development isn’t a brand new field anymore. Most problems are well known and therefore have well known solutions. So it pretty much always comes down to management not wanting to implement the known solutions to the problems because its easier to blame the devs.

Venator, in Infinite Loop

Sometimes a fresh pair of eyes on a code base can reveal some opportunities for big improvements in maintainability 😜

MajorHavoc,

Ahahhahhahha. Ha…ha. Ahem.

Sorry. The idea that any of the opportunities for improvement at my last “job A” code base might need “revealed” struck me as really funny.

Venator,

Sometimes there’s an opportunity to delete it and start again 😜

tkk13909,

Looks like we found the hr employee! Get 'im Bois!

Venator,

Lol, nah I’m a developer.

gregorum, (edited )

Sometimes it takes a new dev coming in for management to give the greenlight for a major overhaul. It’s shitty, but it’s true.

myster0n, in Every goddamn time

THIS ACTION IS NOT ALLOWED > OVERRIDE ACCESS GRANTED

rtxn, (edited )

No, no, first you need to reroute, to be able to patch it through, and THEN you can override the command sequence in order to exploit parallelisms at the core root interface.

Alawami,

sudo !!

extratone, in Fitbit Clock Face
@extratone@lemmy.world avatar

Datestamp horror.

bjoern_tantau, in Multifactor auth done right
@bjoern_tantau@swg-empire.de avatar

They forgot something old, something borrowed and something blue.

muntedcrocodile,
@muntedcrocodile@lemmy.world avatar

da ba dee da ba di

reflex,
@reflex@kbin.social avatar

da ba dee da ba di

Mm-mmm, waffles.

lemann,

🤢

AVincentInSpace, (edited ) in Manager: This task only takes 30 minutes. Why did it take you the whole day?

Every time I commit I have to look through git diff, figure out what the hell I actually did, come up with something intelligent to say about jt, possibly split the commit into multiple commits if I changed multiple things, do some shuffling with git reset and git add

For some reason all my personal projects are all like 4K SLoC with 50 total commits, all of which include apologies for not doing more smaller commits

PoolloverNathan,

^psst,^ ^git^ ^add^ ^-p^

etchinghillside, (edited )

Remind me what -p does.

Edit: never mind - I see it mentioned below.

PoolloverNathan,

Patch add - it shows you particular changes you made, and you choose whether or not to include them in the commit. (You can then use git stash -k to stash only the changes you did not add, so you can test before you commit.)

Anticorp,

There’s a bigger issue than your commit message if you don’t even know what you just coded and are committing.

AVincentInSpace, (edited )

You see, sometimes I code something, go to bed before finishing it, come back, decide not to commit because then I’d have to think of a commit message and I just want to code, start working on an unrelated feature, do that for a couple days, get distracted by life stuff and put the project down for a few weeks/months, rinse and repeat, and then I finally get around to writing a commit message because I’m about to start a huge change and I want a restore point and I’m like. Okay, it’s been like 3 months since my last commit, I’m pretty sure my code can now do something it couldn’t 3 months ago but come on, I can’t even remember what I had for lunch last Thursday

I’m well aware this is terrible practice but I don’t know how to stop doing it

dukk,

Commit more often. Maybe work in a different feature branch, and don’t be afraid to commit your half-working crappy code. If it’s a personal project/fork, it’s totally acceptable to commit often with bad commit names and small unfinished changes: you can always amend/squash the commits later. That’s how I tend to work: create a new branch, work on the feature, rebase and merge (fast forward, no merge commit). Also, maybe don’t jump around working on random features :P

AVincentInSpace, (edited )

but…but new feature shiny

Fr tho this is all excellent advice

ExtraMedicated,

Jumping around to random features is how my ADHD brain works most efficiently.

Slotos,

Good news, TDD is methylphenidate of software development!

adrian783,

you can setup a on-save script to force you to commit when the number of changes is greater than a certain number from the previous commit.

Anticorp,

You can help yourself a lot here by making commits every time you make a meaningful change. A feature doesn’t need to be complete to commit major checkpoints along the path to completion. That’s what feature branches are for. Commit often. It’ll help you think of messages, and it’ll help you recover in the case of catastrophe.

adrian783,

it means you commit too infrequently. your commit messages should be able to describe what u just did within 10 words.

akkajdh999,

I just get too excited about actually implementing/fixing something (random things that I see along the way) more than commit ceremony (nobody will care about it in my project anyway other than one random guy who gave the repo a star)

oce,
@oce@jlai.lu avatar

Nah, I’m that guy, I gave your repo a star for the effort, but I’m not reading your history.

PixxlMan,

I spend much time splitting them up inside visual studio by file and individual lines changed to try and separate my many simultaneous changes into several somewhat usable commits. If I was stupid enough to make some big refactor at the same time I might just have to throw in the towel… It’s really painful after a few weeks to try and pick up the pieces of what I was doing but never commited too lol.

gregorum, (edited ) in Bug Thread

“So, how did you two meet?”

“He spent 2 years on a linux support forum helping me fix and nVidia driver issue. we’ve been married for 6 years this March.”

Dicska,

This Arch

Daxtron2, in Fitbit Clock Face

Everything’s a string 😢

lseif,

Everythings an object 😰

Daxtron2,

lua tables all the way down

marcos, in isEven API

Oh, bummer, my number isn’t supported by the free version:

api.isevenapi.xyz/…/87643895874857367499567729846…

fckreddit,

Easy workaround, just test the last digit. If it is even, the entire number is even, else odd.

marcos,

That’s preposterous! Next time you’ll tell me the language I’m using has a builtin operator that test if a number can be divided by another!

aaaa,

That’s not even supported by the enterprise version. You’re going to need a special agreement with the iseven people to support numbers like that

captainjaneway,
@captainjaneway@lemmy.world avatar

Just divide that number by two until it’s small enough to make the request under the free version.

taaz,

pretty sure that has to be against their TOS

/s

mormegil,
@mormegil@programming.dev avatar

That’s against the terms of math :-)

brokenlcd, in Always

I’m not sure why but i just flat out work better at night when everyone is asleep, pretty mutch all of the “last modified” time on my project files is from 10 pm to 3 am

idunnololz,
@idunnololz@lemmy.world avatar

My sweet spot is 1am to 4am no joke.

BiggestBulb,
@BiggestBulb@kbin.run avatar

Same here

xmunk,

I’ve been working remotely from Barcelona for three months… My hours are 3pm to 11pm local time, it’s fucking bliss.

xor,

no distractions…
one metaphor i heard is, holding a program in your head is like building a house of cards, every time a phone rings or something breaks your concentration, you have to rebuild the house

ripcord,

every time a phone rings or something breaks your concentration, you have to rebuild the house

Holy moley.

I guess this is why programmers generally don’t do construction.

xor,

house of cards

Croquette,

Some people are more diurnal, some are more nocturnal.

My productivity peak is between 8PM and 11PM, but with kids this is impossible.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • programmer_humor@programming.dev
  • localhost
  • All magazines
  • Loading…
    Loading the web debug toolbar…
    Attempt #

    Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 21094400 bytes) in /var/www/kbin/kbin/vendor/symfony/http-kernel/Profiler/FileProfilerStorage.php on line 171

    Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 10502144 bytes) in /var/www/kbin/kbin/vendor/symfony/error-handler/Resources/views/logs.html.php on line 38