3 ms·
The problem with languages where everything is possible syntactically is that everything is possible syntactically. You're no longer dealing with a language th
by wvenable 18y ago
The problem with languages where everything is possible syntactically is that everything is possible syntactically. You're no longer dealing with a language that everyone speaks and understands -- instead you have to learn to local dialect just to get started. If the programmer before you was a total git, you'll be in more trouble than if you'd use a more constrained language. This is why most languages after C++ have avoided operator overloading.
- swannodette 18y agoEvery serious (sane) large coding project has: 1. Standard coding practices & constraints 2. Code review So what were the reasons again that a team shouldn't use the most powerful language at hand ;)
- tolmasky 18y agoI think his point is when you have to use parts of other projects. Unless you are operating in a complete vacuum, this will still be an issue when using other libraries, etc. Also, the "coding practices, constraints, and code review" can be used to hand wave absolutely every language shortcoming aside.
- mbrubeck 18y ago> This is why most languages after C++ have avoided operator overloading. Except for C#, PHP, Python, Ruby, Perl, Haskell, Io, Lua, Scala, Groovy, D, F#, and even Visual Basic. Really the only major post-C++ languages to avoid operator overloading were Java, JavaScript, and Objective-C. I've seen an argument that Java learned the wrong lessons from C++. They saw how complicated operator overloading was in C++ and avoided it, despite the fact that the worst complications in came from mixed pointer/value/reference calling conventions (which of course wouldn't affect Java). C# proves that it's completely possible for a Java-like language to have safe and easy operator overloading.
- russell 18y agoAnd in Java you get such idiocies as == for primitives and equals for objects. Would it have been so hard to translate == into a.equals(b)?
- 10ren 18y agoThey have different meanings in Java a == b // same object a.equals(b) // same value
- cousin_it 18y agoIf Java had made primitives syntactically behave like immutable Objects with a proper implementation of equals(), Russell's suggestion would've made obvious sense and the language would've made more sense overall. The road not taken.
- 10ren 18y agoHow does this overcome the need for two kinds of equality for objects? i.e. whether two pointers refer to the same address vs. whether they point to different addresses (or the same) that contain objects with the same value, according to that object's definition of equals(). Do you mean that the present == for primitives should be replaced with .equals(), and the == for object reference equality should be replaced by perhaps === or .refEquality(), and then the .equals() for objects should be left alone. and then, == be added as syntactic sugar for .equals().... Are those assumptions what you meant? If so, the same outcome can be achieved with by changing object == to ===, and object .equals() to ==. However, there are reasons for treating primitives as objects other than this. I expect you've a model in mind from some other language that resolves this in along different lines (C# would be one), and so you haven't felt the need to articulate the assumptions needed to make it work. If I've guessed wrongly, can you elaborate please?
- cousin_it 18y agoThe overwhelming majority of actual Java code needs at most one equality operation defined per class. Hamming compression and convention suggest that it be called == . Extensibility suggests that it desugar into .equals() or something like that. For immutable objects like ints or Strings the implementation of equals() should compare internal values, because reference equality for passive immutable things is practically never useful. This should already obviate the majority of explicit calls to equals() in actual Java code, because most of them are comparing Strings anyway. For mutable objects the default implementation of equals() should compare object identity (hashCode), but be overridable if the user wants something exotic. Algorithms and data structures relying on equality, like hash tables, should provide the option of supplying the equality operator or hash function at construction time, just like printf frees the user from the need to commit to one Integer.toString() implementation in perpetuity. This all sounds like a reasonable scheme to me. I can flesh it out in more detail if you request.
- stcredzero 18y agoI think this speaks to the value of the "local dialects" that you have had a chance to learn. In Smalltalk and languages of similar capability, it's possible for a project to develop domain-specific "local dialect" that has prodigious power. Any project that's really worth its salt develops these. Most just develop their own way of doing the same inefficient stuff. Meta-programming is much more powerful than just plain programming. It's also not as widely understood.