GTG3000,

Why use const max = (x, y) => x > y ? x : yinstead of function max(x, y) { return x > y ? x : y } ?

pomodoro_longbreak,

Yoink.

Actually I’ve probably been all of these at various times in my career.

aeharding,
@aeharding@lemmy.world avatar

Procrastinator + troll.

return x

force, (edited )

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


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

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

stingpie,

Ah yes, rust. The language that somehow manages to manages to as verbose as possible, with as much jargonized shorthand that a computer could handle.

aidan,

Exactly, I don’t understand why languages have decided that every keyword needs to be as randomly minified as possible. fn, def, rune(ok that’s not minified, just a dumb name), fmt, std. Many of these things aren’t new, but programmers recognize descriptive variable names are important, the same should be true for keywords.

Cihta,
@Cihta@lemmy.world avatar

Wow that’s a very exhausting language. I dropped your code into an online rust to asm converter and it actually wasn’t more! I did try to post it for fun but lemmy kept messing up the code block. Oh well, wasn’t that amusing anyway!

force,

lol that’s not actually how rust is written, it was just a joke

it’d really be written


<span style="color:#323232;">if x > y { x } else { y }
</span>
Cihta,
@Cihta@lemmy.world avatar

Hah thanks for clarifying. I was joking too and it’s a shame I couldn’t post the results.

Though I admit i don’t know anything about rust. I’m sure I’d like it better than the proprietary garbage i use now that just gets converted to ASM / PLC code in the end. But I can’t skip the middle man. I’m not gonna try but probably 30mins for me to “write” the above.

Besides, how do you make money if I can code something in an hour as opposed to 2 days?

force,

deleted_by_author

  • Loading...
  • Cihta,
    @Cihta@lemmy.world avatar

    No no no you misunderstood me.

    I was being honest, I know nothing of rust. I have however used python in embedded systems with positive results. The product didn’t make it but for other reasons.

    Funny you mention java, that’s sorta what I’m stuck in but not like you think. Beyond the fact that it’s a bloated nightmare.

    I’m just a low-level programmer at heart but I have bills to pay. The rust stuff was all just a joke… i don’t know it but maybe i should. Thanks for the info.

    Saying anymore about what I do is just super embarrassing but i promise i meant no ill will. Excuse my frustration, I’m locked into a proprietary system i have no control over. You would laugh your ass off if you saw it. Anyway, i meant no offense, have a good night!

    Amends1782,

    Isn’t it php?

    cybirdman,

    Master Thief const { Max: max } = Math;

    scroll_responsibly,
    @scroll_responsibly@lemmy.sdf.org avatar

    my $max = $x > $y ? $x : $y;

    Fungah,

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

    Ugh. I’ll never be any good.

    pomodoro_longbreak,

    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.

    Fungah,

    About a year with varying levels of commitment and intensity.

    I kind of just threw myself into the deep end. Which was a rewarding but frustrating experience. My first project was one hot encoding 400gb of reddit porn to try and teach stylegan3 how to make porn. And then turning the function on in stylegan3. And then there was validating the images and ditching the ones that erroted. Resizing the whole datasets. Using ffmpeg to extract stills from the gifs and mp3s

    I found stable diffusion existed like 5 days into actually training it which was bitter sweet. I mean. No way it would have produced actual porn but I was really looking forward to the horror.

    I taught myself as I went along which is a great way to learn but it’s super disheartening when I see the math that’s second nature to anyone whose studied this stuff academically… I don’t like math. In fact I hate it, and no matter how skilled (or not) a coder I become I’ll never learn calculus sometimes makes it all feel like a fools errand.

    pomodoro_longbreak,

    I also hate math, and am jealous of people who are good at it. I get anxiety just doing simple multiplications, and have to look everything up. That said, I’m a senior platform developer, and earn more than anyone else in my family, so like… math helps a lot, but you don’t neeed it to be a real dev. Certainly not to be a hobbyist/hacker, like yourself.

    Theharpyeagle,

    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.

    affiliate,

    here’s another mathematical approach (that has the added benefit of only working when x and y are both positive).

    let f denote the linear functional on ℝ^2^ defined by f(1,0) = x and f(0,1) = y (and extend by linearity). then the operator norm || f || is equal to max(x,y).

    dinckelman,

    2, but I’m incredibly embarrassed to say that I’ve had to do 9 before

    tigerhawkvok,

    9 is objectively better if you have untrusted inputs and need a stable failure mode.

    dinckelman,

    That was precisely the reason. I prefer strongly typed languages languages, so it just felt gross to write that

    Shhalahr,

    Procrastinator.

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

    snowcatridge10,

    Thief

    marco,
    @marco@beehaw.org avatar

    And not feeling one byte bad about it :p

    writeblankspace,

    Thief, or Procrastinator.

    wethegreenpeople,

    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,

    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.

    Snazz,

    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

    DumbAceDragon,
    @DumbAceDragon@sh.itjust.works avatar

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

  • All
  • Subscribed
  • Moderated
  • Favorites
  • programmerhumor@lemmy.ml
  • khanakhh
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • osvaldo12
  • ethstaker
  • Youngstown
  • mdbf
  • slotface
  • rosin
  • everett
  • ngwrru68w68
  • kavyap
  • InstantRegret
  • megavids
  • GTA5RPClips
  • Durango
  • normalnudes
  • cubers
  • tacticalgear
  • cisconetworking
  • tester
  • modclub
  • provamag3
  • anitta
  • Leos
  • JUstTest
  • lostlight
  • All magazines