General statistics
List of Youtube channels
Youtube commenter search
Distinguished comments
About
Mikko Rantalainen
ThePrimeTime
comments
Comments by "Mikko Rantalainen" (@MikkoRantalainen) on "Prime Reacts: From C to C++ to Rust to Haskell" video.
32:05 The Haskell line calculate :: Int -> Int -> Int is Haskell way of writing type definition for the function. In a mathematical sense it makes no difference if the function return type is considered to be {takes one argument and returns a function that takes one argument and returns an integer} or {a function that takes two integers and returns one} when both are called with two arguments. As a result, Haskell developers seem to believe that they want to define functions in mathematical sense. I can read that syntax but I most definitely don't like it. It appears that Haskell developers do anything they can do avoid using any parenthesis or commas. And as a result we have this Int -> Int -> Int stuff and dollar sign at the middle of the line.
1
@cktken3336 Do you agree that "$" is just syntactic sugar and could be replaced everywhere with wrapping the rest of the line in parenthesis? Its sole purpose is to avoid writing parenthesis, nothing more. And JavaScript supports partial application, too. It just requires using bind() syntax to implement that. And with tracing JIT compilers in modern JavaScript engines you also get high performance with that.
1
Use Allman-8 style and you'll automatically avoid too much nesting from the start because the code starts to look really ugly really fast. I've been writing code professionally for 20+ years and I'm still thinking that if we typically use Allman style to teach programming, why ever change to anything less understandable even if it can compress more characters to smaller space?
1
25:09 I think this is just another example why early return is so good. It declares an edge case and clearly implements special handling for that.
1
36:30 More instructions == slower is not always correct. It really depends on instructions and how those will be decoded to micro-ops and how those get executed in the CPU. I wouldn't even bother looking at the amount of instructions, just profile it. And if you're actually interested in instruction count for some reason, compile with with -Os which asks for smaller instruction count.
1
22:00 I think "e" is for integer (when you consider how the "i" in integer is pronounced). I'd definitely use i, n or k for this kind of context.
1
15:33 Some developers have weird allergy against doing multiple return statements and they end up with crap like stuffing a lot of code in one ternary statement and pretend that the code looks nice. Always do early return if possible and avoid all the nesting and complex multi-line statements. If you write a long line of code for anything but data (e.g. user visible error message is data and doesn't need to be wrapped – just write the whole error message on one line, please) you're doing something wrong. If you need to wrap your statement because it cannot fit on one line, that statement is trying to do too much to be both readable and maintainable.
1
I never understand C++ naming in std namespace. Who thought std::views::iota() was better than std::views::range() or maybe even std::range::integer()?
1
19:50 100% agree for explicit return! I even write the keyword return for my lambda functions just to make it extra clear what's happening.
1