▲ 164 ▼ Tabs are objectively better than spaces - gomakethings.com (gomakethings.com) submitted 2 years ago by mac@programming.dev to c/programming@programming.dev 176 comments fedilink hide all child comments
[–] xigoi@lemmy.sdf.org -1 points 2 years ago (1 child) When you're operating on such a low level of abstraction, it's no wonder you don't need deep nesting. permalink fedilink source parent hideshow 2 child comments replies: [–] IRQBreaker@startrek.website 1 point 2 years ago (1 child) Oh, I've done my fair share of C++ and Python as well. But you got to agree with me that when you are on your fourth indented "if case" it's time to step back and think about what you are trying to achieve. I mean it's probably going to work, but probably also very hard to maintain that type of code. permalink fedilink source parent hideshow 2 child comments replies: [–] xigoi@lemmy.sdf.org 2 points 2 years ago (1 child) How would you implement, for example, Gaussian elimination with at most 3 levels of nesting? permalink fedilink source parent hideshow 2 child comments replies: [–] JesperZ@programming.dev 2 points 2 years ago* (1 child) Abstraction. The solution for all levels of nesting. permalink fedilink source parent hideshow 2 child comments replies: [–] xigoi@lemmy.sdf.org 2 points 2 years ago* (last edited 2 years ago) (1 child) Be specific. Which exact part would you abstract away and how? permalink fedilink source parent hideshow 2 child comments replies: [–] JesperZ@programming.dev 3 points 2 years ago* There a many ways to implement abstractions, but it’s highly dependent on the language in question. You could simply refactor each level of nesting into its own function, with all dependents provided as parameters instead of scoped variables. You could then flatMap to avoid a bunch of nested looping, favoring a linear approach that’s often easier to reason about. You could go all out and refactor all your conditional statements away, in favor of the Either monad. You’d then have a number of functions, each doing one thing (including no nesting), and a main function gluing it all together, linearly. That is a pattern you can always apply; there’s nothing controversial about it, and on a similar note there’s nothing particularly challenging about Gaussian elimination. permalink fedilink source parent
[–] IRQBreaker@startrek.website 1 point 2 years ago (1 child) Oh, I've done my fair share of C++ and Python as well. But you got to agree with me that when you are on your fourth indented "if case" it's time to step back and think about what you are trying to achieve. I mean it's probably going to work, but probably also very hard to maintain that type of code. permalink fedilink source parent hideshow 2 child comments replies: [–] xigoi@lemmy.sdf.org 2 points 2 years ago (1 child) How would you implement, for example, Gaussian elimination with at most 3 levels of nesting? permalink fedilink source parent hideshow 2 child comments replies: [–] JesperZ@programming.dev 2 points 2 years ago* (1 child) Abstraction. The solution for all levels of nesting. permalink fedilink source parent hideshow 2 child comments replies: [–] xigoi@lemmy.sdf.org 2 points 2 years ago* (last edited 2 years ago) (1 child) Be specific. Which exact part would you abstract away and how? permalink fedilink source parent hideshow 2 child comments replies: [–] JesperZ@programming.dev 3 points 2 years ago* There a many ways to implement abstractions, but it’s highly dependent on the language in question. You could simply refactor each level of nesting into its own function, with all dependents provided as parameters instead of scoped variables. You could then flatMap to avoid a bunch of nested looping, favoring a linear approach that’s often easier to reason about. You could go all out and refactor all your conditional statements away, in favor of the Either monad. You’d then have a number of functions, each doing one thing (including no nesting), and a main function gluing it all together, linearly. That is a pattern you can always apply; there’s nothing controversial about it, and on a similar note there’s nothing particularly challenging about Gaussian elimination. permalink fedilink source parent
[–] xigoi@lemmy.sdf.org 2 points 2 years ago (1 child) How would you implement, for example, Gaussian elimination with at most 3 levels of nesting? permalink fedilink source parent hideshow 2 child comments replies: [–] JesperZ@programming.dev 2 points 2 years ago* (1 child) Abstraction. The solution for all levels of nesting. permalink fedilink source parent hideshow 2 child comments replies: [–] xigoi@lemmy.sdf.org 2 points 2 years ago* (last edited 2 years ago) (1 child) Be specific. Which exact part would you abstract away and how? permalink fedilink source parent hideshow 2 child comments replies: [–] JesperZ@programming.dev 3 points 2 years ago* There a many ways to implement abstractions, but it’s highly dependent on the language in question. You could simply refactor each level of nesting into its own function, with all dependents provided as parameters instead of scoped variables. You could then flatMap to avoid a bunch of nested looping, favoring a linear approach that’s often easier to reason about. You could go all out and refactor all your conditional statements away, in favor of the Either monad. You’d then have a number of functions, each doing one thing (including no nesting), and a main function gluing it all together, linearly. That is a pattern you can always apply; there’s nothing controversial about it, and on a similar note there’s nothing particularly challenging about Gaussian elimination. permalink fedilink source parent
[–] JesperZ@programming.dev 2 points 2 years ago* (1 child) Abstraction. The solution for all levels of nesting. permalink fedilink source parent hideshow 2 child comments replies: [–] xigoi@lemmy.sdf.org 2 points 2 years ago* (last edited 2 years ago) (1 child) Be specific. Which exact part would you abstract away and how? permalink fedilink source parent hideshow 2 child comments replies: [–] JesperZ@programming.dev 3 points 2 years ago* There a many ways to implement abstractions, but it’s highly dependent on the language in question. You could simply refactor each level of nesting into its own function, with all dependents provided as parameters instead of scoped variables. You could then flatMap to avoid a bunch of nested looping, favoring a linear approach that’s often easier to reason about. You could go all out and refactor all your conditional statements away, in favor of the Either monad. You’d then have a number of functions, each doing one thing (including no nesting), and a main function gluing it all together, linearly. That is a pattern you can always apply; there’s nothing controversial about it, and on a similar note there’s nothing particularly challenging about Gaussian elimination. permalink fedilink source parent
[–] xigoi@lemmy.sdf.org 2 points 2 years ago* (last edited 2 years ago) (1 child) Be specific. Which exact part would you abstract away and how? permalink fedilink source parent hideshow 2 child comments replies: [–] JesperZ@programming.dev 3 points 2 years ago* There a many ways to implement abstractions, but it’s highly dependent on the language in question. You could simply refactor each level of nesting into its own function, with all dependents provided as parameters instead of scoped variables. You could then flatMap to avoid a bunch of nested looping, favoring a linear approach that’s often easier to reason about. You could go all out and refactor all your conditional statements away, in favor of the Either monad. You’d then have a number of functions, each doing one thing (including no nesting), and a main function gluing it all together, linearly. That is a pattern you can always apply; there’s nothing controversial about it, and on a similar note there’s nothing particularly challenging about Gaussian elimination. permalink fedilink source parent
[–] JesperZ@programming.dev 3 points 2 years ago* There a many ways to implement abstractions, but it’s highly dependent on the language in question. You could simply refactor each level of nesting into its own function, with all dependents provided as parameters instead of scoped variables. You could then flatMap to avoid a bunch of nested looping, favoring a linear approach that’s often easier to reason about. You could go all out and refactor all your conditional statements away, in favor of the Either monad. You’d then have a number of functions, each doing one thing (including no nesting), and a main function gluing it all together, linearly. That is a pattern you can always apply; there’s nothing controversial about it, and on a similar note there’s nothing particularly challenging about Gaussian elimination. permalink fedilink source parent