I don't understand Java....

Started by
33 comments, last by timmay314 20 years ago
quote:Original post by Raghar
It''s strange because it''s just a syntax sugar.

Everything except for CPU microcode is syntax sugar(sic).
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Advertisement
quote:Original post by Raghar
What is this.
A*B
Is it addition, or sorting?

What is this:

a.multiply(b);

Is it multiplication, or is it sorting?
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
quote:Original post by Arild Fines
quote:Original post by Raghar
It''s strange because it''s just a syntax sugar.

Everything except for CPU microcode is syntax sugar(sic).


No, if a language construct saves you a significant amount of time, or makes your life significantly easier, then it''s not "sugar".

Operator overloading does not save a significant amount of time. It is exactly the same amount of work to call a function through an overloaded operator, as it is to call a normal function. And it takes like 5 seconds to change a function call between the two styles.
Imagine if Java had the same number of operator as J (APL''s descendant), how would you feel about operator overloading then?
quote:Original post by GnuVince
quote:Original post by hpolloni
quote:Original post by Oluseyi
I concur. The rationale was that operator overloading is often abused, and the Java mantra is to eliminate anything that is potentially confusing, obscure or "dangerous". It''s a pretty tame language. Nevertheless, the C++ operator overloading syntax is fugly, unintuitive and necessitates the addition of another keyword (operator). The elegant way to do it would be to have certain specially-named functions (perhaps with leading underscores, indicating their reserved status) which, when implemented, were evaluated as symbolic operators.


Oluseyi is now officially a D fan


Exactly like Python too:

class MyClass:    def __add__(self, rhs):        # Do stuff        def __getitem__(self, index):        # Do stuff    def __setitem__(self, index, value):        # Do stuff  


But I''m not fan of this. What is __setitem__? I like how Ruby does it:
class MyClass  def +(rhs)    # Stuff  end  def [](index)    # Stuff  end  def []=(index, item)    # Stuff  endend  




i didn''t know python support operator overloading, you learn something everyday,well my python knowledge is really limited,and my ruby knowledge too,heck the only thing i know is C,and some C++,oh and perl,and some Java too. And about operator overloading,is a language feature,so if you want to use it,use it,simple isn''t it?,the only thing you have to worry is that your code is readable and understandable, use comments, and etc etc. My criteria for operator overloading is only use it if it has a mathematical meaning(i.e. operating vectors, complex numbers,etc).

that''s my two cents

This topic is closed to new replies.

Advertisement