this post was submitted on 22 Oct 2023
620 points (95.7% liked)

Programmer Humor

32568 readers
764 users here now

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

Rules:

founded 5 years ago
MODERATORS
 
top 50 comments
sorted by: hot top controversial new old
[–] SuperIce@lemmy.world 131 points 1 year ago (3 children)

Why would you use anything other than Math.max?

[–] SzethFriendOfNimi@lemmy.world 81 points 1 year ago

Some of us have trust issues. Or worked with Java.

Which, now that I think about it, comes to the same thing.

[–] Zagorath@aussie.zone 17 points 1 year ago* (last edited 1 year ago) (1 children)

Well, the question sort of implies that you're needing to implementing Math.max yourself, for whatever reason. Probably as an exercise. It doesn't make sense to reuse a library that implements the feature if you're explicitly being asked how you would implement it yourself.

[–] demonen@lemmy.ml 14 points 1 year ago (1 children)

This is why I think school and interviews are like a whole different universe from the one where actual work gets done.

[–] Zagorath@aussie.zone 8 points 1 year ago (4 children)

In some ways they can be wholly different, but I don't think this is a good example of it.

Any programmer who cannot implement "take two numbers, return the larger one" is clearly not very competent. Even though you're never going to literally need to implement Math.max yourself at work, you are going to need basically the same types of skills. Probably 95% of the work I do day-to-day is stuff you'd learn in your first year at uni, and this just shows that you've got that ability.

In practice, the best interviews I've had usually set a slightly more complicated task as a do-in-your-own-time problem and then go through what you did in the actual interview. Problems like "read a list of names in the form , each name on a separate line, from a text file. Sort the names by last name, then by other names. Output to another text file. Include unit tests." They wouldn't then expect you to re-implement the sorting algorithm itself, but more want to look at the quality of code, extensibility, etc.

More basic questions like the one in the OP, or fizzbuzz, are decent as well, and a big step up from lame questions like "what does SOLID stand for? What does the Liskov substitution principle mean to you?" Even if they're not quite as valuable as a miniature project.

load more comments (4 replies)
load more comments (1 replies)
[–] lwhjp@lemmy.sdf.org 76 points 1 year ago

TDD

const max12 = (x, y) => {
    if (x === 1 && y === 2) {
        return 2;
    } else if (x === 7 && y === 4) {
        return 7;
    } else {
        return x;
    }
};
[–] davel@lemmy.ml 65 points 1 year ago (2 children)

Thief. Writing code is for chumps, and the more code you right, the more of a chump you are.

[–] cheerjoy@lemmy.world 31 points 1 year ago (1 children)

why say many word when few do trick

[–] independantiste@sh.itjust.works 8 points 1 year ago* (last edited 1 year ago)

Why 🗣️📈 word when 😃👍

[–] tiredofsametab@kbin.social 13 points 1 year ago (1 children)

Writing code is for chumps, and the more code you right, the more of a chump you are.

So you're the one in there wronging up my code?

[–] davel@lemmy.ml 9 points 1 year ago* (last edited 1 year ago)

It’s too late now to wright my wrongh ¯\_(ツ)_/¯

[–] canihasaccount@lemmy.world 48 points 1 year ago (2 children)

Where's the Julia programmer that hits every one of these with @benchmark and then works for six hours to shave three nanoseconds off of the fastest one?

(Example: https://discourse.julialang.org/t/faster-bernoulli-sampling/35209)

load more comments (2 replies)
[–] kewko@lemdro.id 30 points 1 year ago (5 children)

Mathematician 2 kinda blew my mind, kinda obvious, just can't believe I was never taught or thought about it.

load more comments (5 replies)
[–] neosheo@discuss.tchncs.de 25 points 1 year ago (1 children)

Thief gang. Why stand on shoulders of giants if you're not using it to your advantage?

[–] aeharding@lemmy.world 24 points 1 year ago

Procrastinator + troll.

return x

[–] Snazz@lemmy.world 24 points 1 year ago

Bit hacker 2 is really fascinating. It uses a bit mask of all 1s (-1) or all 0s (0) and takes advantage of the fact that y ^ (x ^ y) = x and y ^ 0 = y

[–] Eufalconimorph@discuss.tchncs.de 21 points 1 year ago (2 children)
#define max(x,y) ( { __auto_type __x = (x); __auto_type __y = (y); __x > __y ? __x : __y; })

GNU C. Also works with Clang. Avoids evaluating the arguments multiple times. The optimizer will convert the branch into a conditional move, if it doesn't I'd replace the ternary with the "bit hacker 2" version.

load more comments (2 replies)
[–] force@lemmy.world 21 points 1 year ago* (last edited 1 year ago) (9 children)

wtf kind of cursed programming language is this? JS? it's so ugly, in no universe should a function look like that

but obviously as a rust enjoyer i have to do it like

fn max ⟨T: PartialOrd + Copy⟩(nums: ⁊[T]) -> Option⟨T⟩ {
    let mut greatest: ⁊T = ⁊nums[0];
    match nums.len() {
        0 => None,
        1 => Some(*greatest),
        _ => {
            for num in nums {
                if num > greatest {
                    greatest = num;
                }
            }
            Some(*greatest)
        }
    }
}

edit: lemmy formatting REALLY hates references and generics it seems... time to go back to medieval times

load more comments (9 replies)
[–] driving_crooner@lemmy.eco.br 20 points 1 year ago* (last edited 1 year ago) (8 children)

Mathematician 3

Max(x, y) = floor(ln(e^x + e^y))

load more comments (8 replies)
[–] Shhalahr@beehaw.org 16 points 1 year ago

Procrastinator.

Okay, but seriously: "Thief". Why reimplement it if it’s already available in the language?

[–] snowcatridge10@beehaw.org 14 points 1 year ago (1 children)
load more comments (1 replies)
[–] cybirdman@lemmy.ca 13 points 1 year ago

Master Thief const { Max: max } = Math;

[–] wethegreenpeople@sopuli.xyz 12 points 1 year ago (1 children)

Engineer I guess... Thief is the objectively better enterprise programmer option but I don't know why I always forget about it and just write a ternary ¯⁠\⁠_⁠(⁠ツ⁠)⁠_⁠/⁠¯

[–] mindbleach@sh.itjust.works 11 points 1 year ago

JS instills distrust. Rely on built-in sort? It's alphanumeric. Rely on built-in reverse? It modifies your array. Copy an array? No you didn't.

Yeah no kidding we bang out a kata in a dozen characters. I don't even believe in order of operations at this point. I've been routinely betrayed.

[–] whaleross@lemmy.world 11 points 1 year ago

One, two and nine. Depending on the project, depending on the requirements.

[–] DumbAceDragon@sh.itjust.works 10 points 1 year ago

Either engineer or bit hacker, depending on whether or not I'm trying to avoid branching.

[–] bstix@feddit.dk 10 points 1 year ago* (last edited 1 year ago) (1 children)

And then your customer changes their mind. Instead of two numbers, they will now input three numbers. How easy will it be for you to change your code?

And then the customer changes their mind. Instead of three numbers, they will now input any series of numbers. How easy will it be for you to change your code? And why didn't you already do this is the previous step?

And then the customer changes their mind. Instead of any set of numbers, they will now input numbers and text. How easy will it be to change your code?

And then the customer changes their mind. They now have no idea of what they're sending you or if they're even sending you anything. Nevermind the code now, you already did that in the previous step, right? How easy will it be to explain what you're invoicing them for?

[–] Natanael@slrpnk.net 8 points 1 year ago (1 children)

How easy will it be to explain what you're invoicing them for?

By the hour I presume

load more comments (1 replies)
[–] Fungah@lemmy.world 10 points 1 year ago (2 children)

Reminded of how truly little I know about programming despite the time have spent doing it

Ugh. I'll never be any good.

[–] Theharpyeagle@lemmy.world 11 points 1 year ago

Listen, in industry programming (and for personal projects if you want to get them done), the thief is the way to go. By all means, challenge yourself to understand each of these functions, but 99% of day to day development will not look like this.

[–] pomodoro_longbreak@sh.itjust.works 6 points 1 year ago (2 children)

How much time have you spent doing it? What part didn't you understand? If it's the bit shifting stuff, don't worry about it - hardly anyone actually knows how that works unless they look it up.

load more comments (2 replies)
[–] PeriodicallyPedantic@lemmy.ca 9 points 1 year ago* (last edited 1 year ago)

If thief is actually an option, then thief.

Otherwise probably procreator or engineer 😅😬

Edit: errrrr that was supposed to say "procrastinator" 😬dyac

[–] maegul@lemmy.ml 8 points 1 year ago* (last edited 1 year ago)

Otherwise, realistically, I’m prob the worst of all worlds … the procrastinator waiting/hoping to be the pair programmer that has hopefully remembered to just be the thief.

[–] drew_belloc@programming.dev 8 points 1 year ago

I'm the first and the last, it depends on my mood

[–] peyotecosmico@programming.dev 6 points 1 year ago

I'm in this post and I'm offended.

[–] Moxvallix@sopuli.xyz 6 points 1 year ago

I’m number 11.

[–] kromem@lemmy.world 6 points 1 year ago

max6(1, 2, 3)

Man that's going to cause some headaches...

[–] cpw@lemmy.ca 5 points 1 year ago

Max11 is all my code. Why doesn't it work????🤔

[–] writeblankspace@lemm.ee 5 points 1 year ago

Thief, or Procrastinator.

load more comments
view more: next ›