Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

how to you feel about the overloaded use of `=` in C?


I'm not sure I understand what you mean. `=` is only assignment in C (or Java, or C#, or most any language I know of). `==` is comparison, being a different operator, one wouldn't say `=` is "overloaded".

Two different operations, two different operators. Yes, C famously makes it easy to miss the extra `=` in if expressions, but that's C specifically, and it's not the fault of the operator, that's actually the fault of automatic conversions from int to bool. Static languages designed after I was born usually require boolean expressions in their `if` statements explicitly.

But `+` and `+.` are the same operation. Or are you saying that adding integers and adding reals are not the same operation, and thus warrant separate operators?


I've begun to like having '+' and '+.' operators in OCaml. Not that I'm never tripped up, I often am, but I can never hide implicit conversions.

Another thing to consider is how you would implement having '+' for both integers and floats. In a language like C, '+' is designed for its numerical types, but what if you want to use it for big ints? Or for vectors? In a language like C++ you can overload operators, in Haskell or Rust operators are part of a typeclass or trait respectively; you need to add extra features to the language and the code generated by '+' is no longer a simple iadd or dadd instruction.

OCaml's choice may not be the best one or the most popular one, but I think it works fine.


Perhaps you know this, but just for the sake of precision and avoidance of doubt: Haskell numerical operations don't actually do any sort of conversion.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: