which way, white man?

which way, white man?

CRIME Shirt $21.68

Yakub: World's Greatest Dad Shirt $21.68

CRIME Shirt $21.68

  1. 1 month ago
    Anonymous

    you're moronic, choose another profession

  2. 1 month ago
    Anonymous

    Mix them together. Have separate functions and the switcher function that just dispatches them.

    • 1 month ago
      Anonymous

      Isn't that the worst of both sides?

      • 1 month ago
        Anonymous

        You mean best of both sides.
        Granted, I haven't written more than a couple hundred lines for a project, so I might change my opinion in the future

  3. 1 month ago
    Anonymous

    print(“anbnc1ndnanbnc3ndn”)

  4. 1 month ago
    Anonymous

    C:
    Get rid of all three functions and just put the print() statements directly there.

    • 1 month ago
      Anonymous

      this is the answer of someone who actually does more than surface level "programming"

      • 1 month ago
        Anonymous

        It's the opposite actually

      • 1 month ago
        Anonymous

        More like the answer of someone who didn't even understand an abstract question

  5. 1 month ago
    Anonymous

    I don't know actually why you would ever do the B way. But it seems so contextual.

  6. 1 month ago
    Anonymous

    don't the literally print different things?
    A prints: a b c3 d
    B prints: a b c1 d a b c3 d

    • 1 month ago
      Anonymous

      There is no hope for you

      • 1 month ago
        Anonymous

        thanks i finally noticed doSomething(1)

  7. 1 month ago
    Anonymous

    on a tech interview - A.
    in 99,999999% of other cases - B
    And any argumentation against B comes from people who do nto care when the final product will be made, if it will be made at all, and even ironically enough - its quality.
    Once the final product has been made and you refactor - A is the way.

    • 1 month ago
      Anonymous

      so A is technologically better but B is "just get things done"?

      • 1 month ago
        Anonymous

        yes. Although i do not even think this, but if i were in the position of my boss on my last job i would not only defend A but also complain, scream, dialite, mald and cry that B he been used.
        Why?
        Well for once - autism. But for 2nd reason - he is a 48 years old dev that wants to go to work, do some really small amount o0f job, go home at 2pm - 4 hours earlier and "work remotely from home"
        In other words: it is easier to complain about code quality than the develop new features.
        I hated the CEO of the company so I had no problem of the boss taking 4 hours brakes. He also came 1 hour late every day... so he was working 3 hours per day. 2 of which were complaining about what we did.

        • 1 month ago
          Anonymous

          no hard feelings to the lead dev - i think it was based how he worked at most 15 hours per week, its just that when i see what devs write and scream and dilate about A. I realize that B is the only feasible way to implement features.

          Also I was working on side projects on my job - so I needed to use B because I were my own CEO in a way and cared about when a feature will be done.

          • 1 month ago
            Anonymous

            True on all points.
            I will add to your "ironically, quality" point that I wholeheartedly agree. You simply can't know when you want the code to be strongly or loosely coupled in the beginning of the project, and many times A and B ends up diverging to a point where A simply isn't readable anymore, or - which happens more often than not - the code will never be touched again, and working an extra hour to "optimize" something makes no difference in the grand scheme of things.

      • 1 month ago
        Anonymous

        I'd argue that you would want A simply to unit test it more easily and also because a, b, and d are all effectively constant. Realistically I'd print a, b, and d in the function where this would be called if it were just logs. You could also make four fuctions, print a, b, c case statement, and print d if you really wanted to avoid unit tests and be DRY.

      • 1 month ago
        Anonymous

        >manual dispatch
        >better
        No. Unless it's a tight, preformance bottleneck loop (the kind where you account for cpu cache lines, and DO NOT USE JS) - manual dispatch is garbage.
        So:
        doSomething(Something1)
        doSomething(Something3)
        Or subclassing, if doSomething is big enougth.

    • 1 month ago
      Anonymous

      I work with people who code like B. They're frickwits. If your code looks like that, you're a frickwit too.

      • 1 month ago
        Anonymous

        >writes shitty slow code
        >complains about other peoples code

      • 1 month ago
        Anonymous

        I would rather write code like B, achieve the goals given to me and probably do some extra work on my own projects during work time, then care about the possibility of maybe, just maybe getting a promotion or something. There is 0 reward for me to think about refactoring the code during the work process - hell, there is some reward for me to lay low and complain about not being able to do it in time because it is too hard as this gives me extra free time.
        It all depends on the reward structure - if it is just a salary at the end of the month, whether i work 8 hours, or 3 hours is irrelevant. But I must look busy.

  8. 1 month ago
    Anonymous

    in The Rust Programming Language this is just:
    fn do_something(n: i32) {
    println!("anbnc{n}nd");
    }

    • 1 month ago
      Anonymous

      C have printf that does the same, and I can write you a C macro that does that, ok, so what?

      • 1 month ago
        Anonymous

        >printf
        heh

    • 1 month ago
      Anonymous

      troony code kys

  9. 1 month ago
    Anonymous

    Depends.
    If your n argument can have a lot of different values and only a few stuff to do in each case, go for A.
    If n can only have a few different values but the amount of stuff you do in each case is huge, go for B.

    • 1 month ago
      Anonymous

      >ITT morons who don't realize the question is about programming principles and not printing some letters

      This is the only good answer

      • 1 month ago
        Anonymous

        Uh...are you okay? People that posted obviously did understand this.

        • 1 month ago
          Anonymous

          Did we read the same thread? Half the replies are the same program just in a different language

  10. 1 month ago
    Anonymous

    I choose C
    print("a");
    print("b");
    print("c1");
    print("d");
    print("a");
    print("b");
    print("c3");
    print("d");

  11. 1 month ago
    Anonymous

    Eh it depends. Its always a balancing act between dry and simplicity/easy to understand. Most of the time A. I could imagine a situation where it'd be silly to try and make some code ultra reusable and importable.

  12. 1 month ago
    Anonymous

    print("a")
    print("b")
    print({
    1: "c1",
    2: "c2",
    3: "c3",
    }.get(n))
    print("d")

    • 1 month ago
      Anonymous

      >pythongays don't even know how to interpolate strings
      Grim.

      • 1 month ago
        Anonymous

        I could have just f"c{n}" but I got the sense that wasn't what OP was going for.

        • 1 month ago
          Anonymous

          What you did wasn't either.

          • 1 month ago
            Anonymous

            Well it turns out OP is moronic so I dunno what you want me to do about that.

          • 1 month ago
            Anonymous

            >OP obviously asking about programming principles
            >everyone posts their shitty code example
            Classic IQfy low IQ moment

          • 1 month ago
            Anonymous

            There is no "programming principle" being displayed here.
            <shared code>
            <arbitrary code>
            <shared code>

            This is too vague to derive any meaningful conventions.

          • 1 month ago
            Anonymous

            It's basically don't repeat code vs just get things done

          • 1 month ago
            Anonymous

            False dichotomy. DRY is always a good principal.
            The difference between A and B is a contextual one, not a stylistic one as is being implied by OP. You want to select the approach that will require the least amount of future code maintenance, which is dependent on the purpose of the code.

  13. 1 month ago
    Anonymous

    function doAB()
    {
    print("a");
    print("b");
    }

    function doD()
    {
    print("d");
    }

    function doSomething1()
    {
    doAB();
    print("c1");
    doC();
    }
    ...

    • 1 month ago
      Anonymous

      typo'd doD in doSomething1 but you get the idea

    • 1 month ago
      Anonymous

      Somehow completely overlooked this and even did the same "...". Weak minds think alike

    • 1 month ago
      Anonymous

      in the white man's language:
      #include <print>

      template <int n>
      auto doSomething() -> void {
      std::println("a");
      std::println("b");
      if constexpr(n == 1){
      std::println("c1");
      }
      if constexpr(n == 2){
      std::println("c2");
      }
      if constexpr(n == 3){
      std::println("c3");
      }
      std::println("d");
      }

      auto main()->int{
      doSomething<1>();
      doSomething<3>();
      }

      function doSomethingStart() {
      print("a");
      print("b");
      }

      function doSomethingEnd() {
      print("d");
      }

      function doSomething1() {
      doSomethingStart();
      print("c1");
      doSomethingEnd();
      }

      ... etc

      What about "do one thing per function and do it well"? Isn't that more important than not reusing code? Philosophical speaking

      • 1 month ago
        Anonymous

        That's what template specialization is for, friend
        template <>
        auto doSomething<3>() -> void {
        ...

  14. 1 month ago
    Anonymous

    in the white man's language:
    #include <print>

    template <int n>
    auto doSomething() -> void {
    std::println("a");
    std::println("b");
    if constexpr(n == 1){
    std::println("c1");
    }
    if constexpr(n == 2){
    std::println("c2");
    }
    if constexpr(n == 3){
    std::println("c3");
    }
    std::println("d");
    }

    auto main()->int{
    doSomething<1>();
    doSomething<3>();
    }

    • 1 month ago
      Anonymous

      Sir you can't be posting such things, we are supposed to pretend C++ is bad

    • 1 month ago
      Anonymous

      my Black person, at my company we have "using namespace std;" in every file. including header files. nothing bad ever happens. do you Black folk really want to spend the rest of your lives spamming std:: everywhere?

      • 1 month ago
        Anonymous

        how does your company feel about auto->void? :^)

      • 1 month ago
        Anonymous

        if you argue in favour of this you are a C++ tourist

    • 1 month ago
      Anonymous

      >auto main()->int
      c++ was a mistake

  15. 1 month ago
    Anonymous
  16. 1 month ago
    Anonymous

    function doSomethingStart() {
    print("a");
    print("b");
    }

    function doSomethingEnd() {
    print("d");
    }

    function doSomething1() {
    doSomethingStart();
    print("c1");
    doSomethingEnd();
    }

    ... etc

  17. 1 month ago
    Anonymous

    doSomething(c)
    {
    print("a")
    print("b")
    print(c)
    print("d")
    }

    doSomething("c1");
    doSomething("c3");

    • 1 month ago
      Anonymous

      print("a")
      print("b")
      print({
      1: "c1",
      2: "c2",
      3: "c3",
      }.get(n))
      print("d")

      in The Rust Programming Language this is just:
      fn do_something(n: i32) {
      println!("anbnc{n}nd");
      }

      print(“anbnc1ndnanbnc3ndn”)

      "print" is just an example, the functionality difference could be anything. stop being autistic.

      • 1 month ago
        Anonymous

        >you can't use an approach other than the two I arbitrarily picked because... you just can't ok?

      • 1 month ago
        Anonymous

        function(callback)
        stuffA
        stuffB
        callback()
        stuffC

        your example is shit, you can't reason with stupid print example because everything works

        • 1 month ago
          Anonymous

          much better

          >you can't use an approach other than the two I arbitrarily picked because... you just can't ok?

          learn from your friend

          also not op but w/e

        • 1 month ago
          Anonymous

          much better
          [...]
          learn from your friend

          also not op but w/e

          >I'm actually referring to some arbitrary abstract situation in which the two things I came up with are the only possible things.
          moron.

          • 1 month ago
            Anonymous

            >I actually wanted to be know the best way to print some letters and numbers on separate lines
            moron

          • 1 month ago
            Anonymous

            What was wrong with

            print("a")
            print("b")
            print({
            1: "c1",
            2: "c2",
            3: "c3",
            }.get(n))
            print("d")

            ?

          • 1 month ago
            Anonymous

            It only supports fairly simple forms of parameterization, you can't have arbitrary code run for different numbers. Unless you make the dict values functions I guess.

          • 1 month ago
            Anonymous

            >ITT morons who don't realize the question is about programming principles and not printing some letters

            This is the only good answer

            MA'AM DO NOT REDEEM THE PRINT STATEMENT! MA'AM DO NOT FIND THE MOST EFFICIENT SOLUTION TO THE PROBLEM PRESENTED TO YOU!
            >YOU ARE NEEDING TO USE THE PROGRAMMING PRINCIPLES! Now open notepad and typing the public class Main, public static void main string args, now doing the system out print line hello world.

  18. 1 month ago
    Anonymous

    B is technically cleaner since parameters are le evil, but WHY are there newlines at the edges?
    In the end, both suck. Leave this board and never come back

    • 1 month ago
      Anonymous

      >parameters are le evil
      I'd rather have 12 parameters on a function than 2 different versions of the same function.
      If there's 50 different ways to call a function, I want a single function whose arguments properly refelct those possibilities, instead of having 50 different overloads.
      That's one of the ugliest things you can find in code.

  19. 1 month ago
    Anonymous
    • 1 month ago
      Anonymous

      > arrow function for no reason
      > horrible function naming
      Don't remind me of work on the weekend pls

      • 1 month ago
        Anonymous

        >for no reason
        this is the best way
        >horrible function naming
        you wrote bullshit names for your functions, I just continued in the same manner

      • 1 month ago
        Anonymous

        arrow functions are superior to your dumbass `function` declaration unless you want to access `this.
        if you need `this` then you're trash anyways outside certain specific cases

  20. 1 month ago
    Anonymous

    John Carmack style

    https://web.archive.org/web/20240510201736/http://number-none.com/blow/john_carmack_on_inlined_code.html

  21. 1 month ago
    Anonymous

    I'm a brown transwoman doe

    • 1 month ago
      Anonymous

      Why would telling anyone this matter? Just provide your code and then frick off.

      • 1 month ago
        Anonymous

        >which way, white man?

  22. 1 month ago
    Anonymous

    It depends entirely on the semantics of the application. If our goal is purely to create this sequential console output, then A. But I wouldn’t ALWAYS go with one structure over another.

  23. 1 month ago
    Anonymous

    I don't program anymore but A is the way I was taught and the way I would if I ever went back.

  24. 1 month ago
    Anonymous

    Obviously A. You want to have as little duplicate code as possible.
    More duplication -> more chance some idiot will accidentally update one function and not the other
    Ideally though you want the switch case statement in a separate function

  25. 1 month ago
    Anonymous

    I've been a dev for six years and I really don't care at this point.

    • 1 month ago
      Anonymous

      yeah, you're fat too, aren't you?

      • 1 month ago
        Anonymous

        6'4 190 pounds so no

        • 1 month ago
          Anonymous

          yeah, you're fat

  26. 1 month ago
    Anonymous

    Neither. In the left version, extract the switch into a separate function.

  27. 1 month ago
    Anonymous

    if "1" "2" and "3" were actions relating to business logic, B; otherwise A.

  28. 1 month ago
    Anonymous

    Depends, if I use the same code more than once I use B, all other cases: A

  29. 1 month ago
    Anonymous

    >71 replies
    this board...
    i wish I knew how many saged the thread

    • 1 month ago
      Anonymous
  30. 1 month ago
    Anonymous

    The only point of a function is to encapsulate correct code. So both are correct if both are correct.

    • 1 month ago
      Anonymous

      >The only point of a function is to encapsulate correct code
      Um...no, it's also so you can call the same code again and optionally pass it arguments.
      Did you go to uni?

      • 1 month ago
        Anonymous

        That would be a routine.

        • 1 month ago
          Anonymous

          A function is a pair of (routine, guarantee of correctness)
          Where "guarantee of correctness" is made by a specification and a lack of jumps, and other features such that no other code can modify your function.
          encapsulation is completely unrelated and irrelevant so you should not have brought it up.

          • 1 month ago
            Anonymous

            I said "encapsulate" and was clearly using it as a verb, such as defined: "Enclose in a capsule or other small container."
            Not in whatever nonsensical way POO cultists use the word "encapsulation"

    • 1 month ago
      Anonymous

      don't think you understand what encapsulation is
      you seem confused, think you're mixing up terms for classes, methods, and functions

      • 1 month ago
        Anonymous

        No. classes are useless, methods are useless. Functions have a use, it's to make sure a routine is correct. That it. If you use them any other way it's misuse

  31. 1 month ago
    Anonymous

    In a case like that it's A, you can't escape the coupling so better to DRY

  32. 1 month ago
    Anonymous

    Imagine being restricted by a featureless language.
    In C++ this is
    #include <print>

    template <int c>
    requires (c >= 1 && c <= 3)
    void doSomething() {
    using std::println;
    println("a");
    println("b");

    if constexpr (c == 1) {
    println("c1");
    } else if constexpr (c == 2) {
    println("c2");
    } else if constexpr (c == 3) {
    println("c3");
    }

    println("d");
    }

    int main(int, char**){
    doSomething<1>();
    doSomething<3>();
    }

    Full static dispatch + precondition enforcement. Feels good using a real lang.

  33. 1 month ago
    Anonymous

    What's the likelihood that you will alter the functions?

  34. 1 month ago
    Anonymous

    A.

  35. 1 month ago
    Anonymous

    BEHOLD
    #!/usr/bin/env sh
    fn(){
    for n in "$@"; do
    for a in a b "c$n" d; do
    echo "$a"
    done
    done
    }
    fn 1 3

  36. 1 month ago
    Anonymous

    function prefix() {
    print("a");
    print("b");
    }

    function suffix() {
    print("d");
    }

    function enclose(fn, pre, suf) {
    pre = pre ?? prefix
    suf = suf ?? suffix

    return () => {
    pre();
    fn();
    suf();
    }
    }

    function doSomething1() {
    print("c1");
    }

    function doSomething2() {
    print("c2");
    }

    function doSomething3() {
    print("c3");
    }

    enclose(doSomething1)();
    enclose(doSomething3)();

    leave yourself options

  37. 1 month ago
    Anonymous

    ```
    function doSomething(n) {
    print("a");
    print("b");

    if (n >= 1 && n <= 3) {
    print("c" + n);
    }

    print("d");
    }

    doSomething(1);
    doSomething(3);
    ```

  38. 1 month ago
    Anonymous

    None ITT is employed

  39. 1 month ago
    Anonymous

    A because my college's CS department docks marks for "poor code structure" including repeating any lines.
    Actually we would lose marks either way for calling print so many times.

  40. 1 month ago
    Anonymous

    def doSomething(other_thing:func):
    print("a")
    print("b")
    other_thing()
    print("c")

    you've gotta be mad moronic if you do it any other way

  41. 1 month ago
    Anonymous

    B > A but the code SHOULD look like this:

    enum flag {
    c1,
    c2,
    c3,
    }

    function doSomething(n : flag) {

    let c = n switch {
    c1 => "c1",
    c2 => "c2",
    c3 => "c3",
    };

    // validation here if necessary

    print("a");
    print("b");
    print(c);
    print("d");
    }

    doSomething(flag.c1)
    doSomething(flag.c3)

    this way you get to "reuse" 3 lines of code, but more importantly, you don't have undefined behavior for numbers outside 1 - 3. and the function is properly parameterized instead of having 3 functions that just happen do to almost the same thing. I absolutely can't stand that kind of thing.

  42. 1 month ago
    Anonymous

    More like which way, wide man, am I right, fatties?

  43. 1 month ago
    Anonymous

    I like B. But A scales better.

  44. 1 month ago
    Anonymous

    Neither, "white" gay
    // Optimize this function for whatever
    // moronic thing was going on in your tiny brain
    const doC(n: number) => {
    if([1,2,3].includes(c)) print(`c${n}`)
    }

    const doSomething (n: number) => {
    print('a')
    print('b')
    doC(n)
    print('d')
    }

  45. 1 month ago
    Anonymous

    I think overcomplicating things before you're even done anything is bad.
    Do you guys ever do a "second take" at the program.
    First take is you just writing the buggies most underliable code just to see how you achieve such a thing.
    Second take you take your time and just more less rewrite it with proper practices in mind.
    That way I feel like I don't need to worry about two things at the same time.

  46. 1 month ago
    Anonymous

    Both are fricking shit. Should be using a dictionary.

  47. 1 month ago
    Anonymous

    i am not white, my name is jamal i am not an arab not a black either, my parents homeland was influenced by muslims ages ago that's where the name from. I am white by color, but my parents' cultrure isn't, it's somewhat isolated from other cultures. i've been grown far away from my parents homeland, in a different culture from their, a european one (somewhat). Even this alien culture i've ditched for online american culture which i live by, larping on a daily basis.
    i don't know who i am, and i have no home. All i have is family and longing for the place i've never been to.

    • 1 month ago
      Anonymous

      >i am not white
      >I am white by color

      • 1 month ago
        Anonymous

        as i've written, culturally i am not white, but peopleof my descendance aren't considered white, despite us being as white as a slav or a brit, not pale though.

        • 1 month ago
          Anonymous

          what the frick is "culturally white" lmao

          • 1 month ago
            Anonymous

            you can find a white persian an a remote mountainous village of iran, but he will not be considered white, in europe at least

          • 1 month ago
            Anonymous

            he would be considered as white as a greek or turk

    • 1 month ago
      Anonymous

      Just act white and change your name to James and you're in

  48. 1 month ago
    Anonymous

    #include <stdio.h>
    #define print_something(x) printf("anbnc%dndn", x)

  49. 1 month ago
    Anonymous

    if
    else if
    else if
    else if
    else if
    else if

  50. 1 month ago
    Anonymous

    I knew this board was a bunch of nocoders

    • 1 month ago
      Anonymous

      I mean, you are here.

Your email address will not be published. Required fields are marked *