▲ 55 ▼ Code Smells Catalog (luzkan.github.io) submitted 2 years ago by lysdexic@programming.dev to c/programming@programming.dev 23 comments fedilink hide all child comments
[–] lysdexic@programming.dev [S] 2 points 2 years ago (2 children) I’ve never heard of evading null with a Null object. This is quite standard, and in fact it's even a safety feature. C++ introduced nullptr defined as an instance of std::nullptr_t explicitly with this in mind. https://en.cppreference.com/w/cpp/language/nullptr This approach is also quite basic in monadic types. permalink fedilink source parent hideshow 4 child comments replies: [–] Kissaki@programming.dev 4 points 2 years ago* (2 children) with this in mind With what in mind? Evading NULL? Languages that make use of references rather than pointers don't have this Dualism. C# has nullable references and nullability analysis, and null as a keyword. What does your reasoning mean in that context? permalink fedilink source parent hideshow 4 child comments replies: [–] FizzyOrange@programming.dev 5 points 2 years ago* (last edited 2 years ago) Languages that make use of references rather than pointers don’t have this Dualism. It's not about references vs pointers. You could easily have a language that allowed "null references" (edit: too much C++; of course many languages allow null references, e.g. Javascript) or one that properly separated null pointers out in the type system. I agree with your point though, using a special Null value is usually worse than using Option or similar. And nullptr_t doesn't help with this at all. permalink fedilink source parent [–] lysdexic@programming.dev [S] 0 points 2 years ago (1 child) With what in mind? Evading NULL? Depends on your perspective. It's convenient to lean on type checking to avoid a whole class of bugs. You can see this either as avoiding NULL or use your type system to flag misuses. Languages that make use of references rather than pointers don’t have this Dualism. C# has nullable references and nullability analysis, and null as a keyword. C#'s null keyword matches the monadic approach I mentioned earlier. Nullable types work as a Maybe monad. It's the same concept shoehorned differently due to the different paths taken by these languages. permalink fedilink source parent hideshow 2 child comments replies: [–] baseless_discourse@mander.xyz 1 point 2 years ago* (last edited 2 years ago) (1 child) as far as I know, C# don't have proper ergonomic monadic bind as in F# (computation expression), Haskell (do expression), and Ocaml (let*), but I could be wrong. permalink fedilink source parent hideshow 2 child comments replies: [–] NigelFrobisher@aussie.zone 1 point 2 years ago Correct. permalink fedilink source parent [–] AbelianGrape@beehaw.org 1 point 2 years ago* (1 child) "Monadic type" has something like three meanings depending on context, and it's not clear which one you mean. One of them is common in math, but not so common in programming, so probably not that. But neither "parametric types with a single argument" nor "types that encode a category-theoretic monad" have the property you say, as far as I know. I imagine you're probably referring to the latter, since the optional monad exists. That's very different from returning null. The inhabitants of Integer in Java, for example, are the boxed machine ints and null. The inhabitants of Optional[Integer] (it won't let me use angle brackets here) are Optional.of(i) for each machine int i, Optional.empty(), and null. Optional.empty() is not null and should not be called a "Null object." It's also not of type Integer, so you're not even allowed to return it unless the function type explicitly says so. Writing such function types is pretty uncommon to do in java programs but it's more normal in kotlin. In languages like Haskell, which don't have null at all, this is idiomatic. permalink fedilink source parent hideshow 2 child comments replies: [–] lysdexic@programming.dev [S] -2 points 2 years ago I think you're trying too hard to confuse yourself. permalink fedilink source parent
[–] Kissaki@programming.dev 4 points 2 years ago* (2 children) with this in mind With what in mind? Evading NULL? Languages that make use of references rather than pointers don't have this Dualism. C# has nullable references and nullability analysis, and null as a keyword. What does your reasoning mean in that context? permalink fedilink source parent hideshow 4 child comments replies: [–] FizzyOrange@programming.dev 5 points 2 years ago* (last edited 2 years ago) Languages that make use of references rather than pointers don’t have this Dualism. It's not about references vs pointers. You could easily have a language that allowed "null references" (edit: too much C++; of course many languages allow null references, e.g. Javascript) or one that properly separated null pointers out in the type system. I agree with your point though, using a special Null value is usually worse than using Option or similar. And nullptr_t doesn't help with this at all. permalink fedilink source parent [–] lysdexic@programming.dev [S] 0 points 2 years ago (1 child) With what in mind? Evading NULL? Depends on your perspective. It's convenient to lean on type checking to avoid a whole class of bugs. You can see this either as avoiding NULL or use your type system to flag misuses. Languages that make use of references rather than pointers don’t have this Dualism. C# has nullable references and nullability analysis, and null as a keyword. C#'s null keyword matches the monadic approach I mentioned earlier. Nullable types work as a Maybe monad. It's the same concept shoehorned differently due to the different paths taken by these languages. permalink fedilink source parent hideshow 2 child comments replies: [–] baseless_discourse@mander.xyz 1 point 2 years ago* (last edited 2 years ago) (1 child) as far as I know, C# don't have proper ergonomic monadic bind as in F# (computation expression), Haskell (do expression), and Ocaml (let*), but I could be wrong. permalink fedilink source parent hideshow 2 child comments replies: [–] NigelFrobisher@aussie.zone 1 point 2 years ago Correct. permalink fedilink source parent
[–] FizzyOrange@programming.dev 5 points 2 years ago* (last edited 2 years ago) Languages that make use of references rather than pointers don’t have this Dualism. It's not about references vs pointers. You could easily have a language that allowed "null references" (edit: too much C++; of course many languages allow null references, e.g. Javascript) or one that properly separated null pointers out in the type system. I agree with your point though, using a special Null value is usually worse than using Option or similar. And nullptr_t doesn't help with this at all. permalink fedilink source parent
[–] lysdexic@programming.dev [S] 0 points 2 years ago (1 child) With what in mind? Evading NULL? Depends on your perspective. It's convenient to lean on type checking to avoid a whole class of bugs. You can see this either as avoiding NULL or use your type system to flag misuses. Languages that make use of references rather than pointers don’t have this Dualism. C# has nullable references and nullability analysis, and null as a keyword. C#'s null keyword matches the monadic approach I mentioned earlier. Nullable types work as a Maybe monad. It's the same concept shoehorned differently due to the different paths taken by these languages. permalink fedilink source parent hideshow 2 child comments replies: [–] baseless_discourse@mander.xyz 1 point 2 years ago* (last edited 2 years ago) (1 child) as far as I know, C# don't have proper ergonomic monadic bind as in F# (computation expression), Haskell (do expression), and Ocaml (let*), but I could be wrong. permalink fedilink source parent hideshow 2 child comments replies: [–] NigelFrobisher@aussie.zone 1 point 2 years ago Correct. permalink fedilink source parent
[–] baseless_discourse@mander.xyz 1 point 2 years ago* (last edited 2 years ago) (1 child) as far as I know, C# don't have proper ergonomic monadic bind as in F# (computation expression), Haskell (do expression), and Ocaml (let*), but I could be wrong. permalink fedilink source parent hideshow 2 child comments replies: [–] NigelFrobisher@aussie.zone 1 point 2 years ago Correct. permalink fedilink source parent
[–] AbelianGrape@beehaw.org 1 point 2 years ago* (1 child) "Monadic type" has something like three meanings depending on context, and it's not clear which one you mean. One of them is common in math, but not so common in programming, so probably not that. But neither "parametric types with a single argument" nor "types that encode a category-theoretic monad" have the property you say, as far as I know. I imagine you're probably referring to the latter, since the optional monad exists. That's very different from returning null. The inhabitants of Integer in Java, for example, are the boxed machine ints and null. The inhabitants of Optional[Integer] (it won't let me use angle brackets here) are Optional.of(i) for each machine int i, Optional.empty(), and null. Optional.empty() is not null and should not be called a "Null object." It's also not of type Integer, so you're not even allowed to return it unless the function type explicitly says so. Writing such function types is pretty uncommon to do in java programs but it's more normal in kotlin. In languages like Haskell, which don't have null at all, this is idiomatic. permalink fedilink source parent hideshow 2 child comments replies: [–] lysdexic@programming.dev [S] -2 points 2 years ago I think you're trying too hard to confuse yourself. permalink fedilink source parent
[–] lysdexic@programming.dev [S] -2 points 2 years ago I think you're trying too hard to confuse yourself. permalink fedilink source parent