Poeng.link
  • Communities
  • Create Post
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
orhtej2@eviltoast.org to Programmer Humor@programming.devEnglish · 7 days ago

Peak code reuse

eviltoast.org

message-square
29
link
fedilink
398

Peak code reuse

eviltoast.org

orhtej2@eviltoast.org to Programmer Humor@programming.devEnglish · 7 days ago
message-square
29
link
fedilink
alert-triangle
You must log in or register to comment.
  • meme_historian@lemmy.dbzer0.com
    link
    fedilink
    English
    arrow-up
    44
    ·
    6 days ago

    stupid comic style drawing of a snake with a derpy face eating its own tail

    • Valmond@lemmy.world
      link
      fedilink
      arrow-up
      3
      ·
      6 days ago

      Oh, Python!

  • katy ✨@piefed.blahaj.zone
    link
    fedilink
    English
    arrow-up
    45
    ·
    edit-2
    6 days ago
    bool isOdd(int num) {  
    	const oddNumbers = [];  
    	for (let i = 1; i <= 10000000; i += 2) {  
      		oddNumbers.push(i);  
    	}  
    	if (oddNumbers.includes(num) {  
    		return true;  
    	}  
    }  
    
    • Malix@sopuli.xyz
      link
      fedilink
      arrow-up
      15
      ·
      7 days ago
      isOdd(-1);
      
      • dev_null@lemmy.ml
        link
        fedilink
        arrow-up
        1
        ·
        6 days ago

        deleted by creator

    • dependencyinjection@discuss.tchncs.de
      link
      fedilink
      arrow-up
      9
      ·
      6 days ago

      isOdd(10000001);

      • katy ✨@piefed.blahaj.zone
        link
        fedilink
        English
        arrow-up
        17
        ·
        6 days ago

        this incident has been reported

    • moseschrute@piefed.social
      link
      fedilink
      English
      arrow-up
      9
      ·
      edit-2
      7 days ago

      Maybe memo just to be safe, but LGTM!

    • marcos@lemmy.world
      link
      fedilink
      arrow-up
      3
      ·
      6 days ago

      You should make it oddNumbers.includes(num%10000000)…

    • schema@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      6 days ago

      And if not, unicorns!

  • FiskFisk33@startrek.website
    link
    fedilink
    arrow-up
    16
    ·
    6 days ago

    https://www.npmjs.com/package/is-even

    don’t look at the weekly downloads if you are faint of heart.

    • Decq@lemmy.world
      link
      fedilink
      arrow-up
      9
      arrow-down
      1
      ·
      edit-2
      5 days ago

      To be fair in a dynamic typed language with dumb string to int coercions, I kinda get why such a library would exists. So it’s more a symptom of terrible language design than modern dependency hell.

      • bobo@lemmy.ml
        link
        fedilink
        arrow-up
        9
        ·
        edit-2
        6 days ago

        in a dynamic typed language with dumb string to int coercions, I kinda get why such a would library exists.

        If string return nan, else % 2

        So it’s more a symptom of terrible language design than modern dependency hell.

        Dependency chain: is-even depends on is-odd which depends on is-number

        • Decq@lemmy.world
          link
          fedilink
          arrow-up
          2
          arrow-down
          1
          ·
          edit-2
          6 days ago

          If string return nan, else % 2

          So now you return a number type if it’s a string and a boolean if it’s an integer. How does that make sense?

          The is-even lib exists to sanitize input by throwing an exception which imho is better.

          Edit: having looked at the code better. Apparently it still allows string coercion (boo). It only checks for non integer numbers.

          • bobo@lemmy.ml
            link
            fedilink
            arrow-up
            1
            ·
            6 days ago

            Good point, but you can do if === true… and else if === false…

            But definitely better to throw an error instead of nan.

          • Decq@lemmy.world
            link
            fedilink
            arrow-up
            1
            ·
            6 days ago

            deleted by creator

    • Hawk@lemmy.dbzer0.com
      link
      fedilink
      English
      arrow-up
      5
      ·
      6 days ago

      If you really want to see some horror, follow the dependencies

    • ThanksForAllTheFish@sh.itjust.works
      link
      fedilink
      arrow-up
      3
      ·
      edit-2
      4 days ago

      https://10xengineersqualityprogramming.github.io/ https://www.npmjs.com/package/@falsejs/falsejs This is hilarious, has 262 of the best useless dependencies. In all seriousness though how does anyone ever audit a npm package, it’s dependency hell!

  • OpenStars@piefed.social
    link
    fedilink
    English
    arrow-up
    19
    ·
    6 days ago

    Boss: don’t spend any time on it, just vibe code a solution.

    You: sure, I enjoy receiving a salary, what could go wrong?

    • Aneb@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      6 days ago

      Mood…

  • cogman@lemmy.world
    link
    fedilink
    arrow-up
    7
    ·
    edit-2
    6 days ago

    Fixed

    boolean isOdd(int num) {
      if(num == 1)
        return true;
      if(num > 0)
        return isEven(num - 1);
      else
        return isEven(num + 1);
    }
    
    boolean isEven(int num) {
      if(num > 0)
        return isOdd(num - 1);
      else
        return isOdd(num + 1);
    }
    
    • affiliate@lemmy.world
      link
      fedilink
      arrow-up
      11
      ·
      6 days ago

      the downside with this approach is that it will eventually terminate. the version in the original post has the advantage of giving me plenty of time to contemplate life’s many mysteries.

      • cogman@lemmy.world
        link
        fedilink
        arrow-up
        4
        ·
        6 days ago

        What can I say, I’m a performance nerd.

    • Valmond@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      6 days ago

      isEeven(∞);

    • Rednax@lemmy.world
      link
      fedilink
      arrow-up
      3
      arrow-down
      2
      ·
      6 days ago

      Why the complicated if statements to check the sign? Just let the number overflow. Would be functionaly the same, and result in much prettier code.

      • cogman@lemmy.world
        link
        fedilink
        arrow-up
        6
        ·
        6 days ago

        That’s a platform dependent change. Overflow is undefined behavior. I’d rather have my code portable so it can run on my Univac 1101.

  • FiskFisk33@startrek.website
    link
    fedilink
    arrow-up
    5
    ·
    edit-2
    6 days ago
    isEven(0) ->
        true;
    isEven(Num) ->
        isOdd(Num-1).
    isOdd(0) ->
        false;
    isOdd(Num) ->
        isEven(Num-1).
    
    • Knock_Knock_Lemmy_In@lemmy.world
      link
      fedilink
      arrow-up
      3
      ·
      edit-2
      6 days ago

      Hmm.

      isEven(-2)…<out of stack error>

  • mercano@lemmy.world
    link
    fedilink
    arrow-up
    3
    ·
    6 days ago

    When it fails, it at least points you to the site where everyone asks for help.

    • orhtej2@eviltoast.orgOP
      link
      fedilink
      English
      arrow-up
      3
      ·
      6 days ago

      Closed as unclear

  • humanspiral@lemmy.ca
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    5 days ago

    easy fix… if infinity return false.

    mathematical breakthrough bonus proof: all numbers are neither even nor odd.

  • guthib_net@programming.devBanned
    link
    fedilink
    arrow-up
    1
    arrow-down
    2
    ·
    edit-2
    6 days ago

    Removed by mod

  • guthib_net@programming.devBanned
    link
    fedilink
    arrow-up
    1
    arrow-down
    1
    ·
    edit-2
    6 days ago

    Removed by mod

Programmer Humor@programming.dev

programmer_humor@programming.dev

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmer_humor@programming.dev

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 1.09K users / day
  • 3.85K users / week
  • 7.22K users / month
  • 18.2K users / 6 months
  • 1 local subscriber
  • 26.4K subscribers
  • 1.01K Posts
  • 15.7K Comments
  • Modlog
  • mods:
  • adr1an@programming.dev
  • Feyter@programming.dev
  • BurningTurtle@programming.dev
  • Pierre-Yves Lapersonne@programming.dev
  • BE: 0.19.11
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org