Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Why default parameter values where not included in Java

Reply
Thread Tools

Why default parameter values where not included in Java

 
 
axer
Guest
Posts: n/a
 
      02-04-2005
I'm looking for any links or documentation that describes why default
parameter values where not included in Java.

I'm not looking for opinion on the matter, or for speculation.

I'm only interested in information that DIRECTLY describes the issue,
and listed in a reputable site or book.

Thank you

 
Reply With Quote
 
 
 
 
Rhino
Guest
Posts: n/a
 
      02-04-2005

"axer" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> I'm looking for any links or documentation that describes why default
> parameter values where not included in Java.
>
> I'm not looking for opinion on the matter, or for speculation.
>
> I'm only interested in information that DIRECTLY describes the issue,
> and listed in a reputable site or book.
>

I've been coding Java for several years and I don't know what you're talking
about.

What default parameters are you looking for? Java and the JVMs seem to have
lots of defaults in them; for example, if you don't specify a memory
parameter, a default amount of memory is assumed.

I'm not sure what you're hoping to find either; it's not that often that a
company will write documentation about why they DIDN'T do something.
Documentation usually covers things that were done, not omitted.

I suppose you *might* find something like interviews with top designers at
Sun explaining why they took a certain path and chose not to take some other
path that could touch on whatever you're after. Sun has some chat
transcripts at java.sun.com so if you look through those you might find what
you want.

But without knowing more clearly what you want, I can't suggest more than
that.

Rhino


 
Reply With Quote
 
 
 
 
Adam Maass
Guest
Posts: n/a
 
      02-04-2005

"Rhino" <(E-Mail Removed)> wrote:
>
> "axer" <(E-Mail Removed)> wrote:
>> I'm looking for any links or documentation that describes why default
>> parameter values where not included in Java.
>>
>> I'm not looking for opinion on the matter, or for speculation.
>>
>> I'm only interested in information that DIRECTLY describes the issue,
>> and listed in a reputable site or book.
>>

> I've been coding Java for several years and I don't know what you're
> talking
> about.
>
> What default parameters are you looking for? Java and the JVMs seem to
> have
> lots of defaults in them; for example, if you don't specify a memory
> parameter, a default amount of memory is assumed.
>


I believe the OP means the C++ feature that looks like this:

void myMethod(int aParameter = 3) {
// do something useful with aParameter
}

Now, you can call myMethod with:

myMethod()


and the parameter 'aParameter' gets set to the value '3'.


But you can also call myMethod with:

myMethod(7)

and the parameter 'aParameter' is set to the value '7'.



I know the OP asked us not to speculate, but this one is so blindingly easy
that it's obvious.

In Java, you simply write overloaded methods:

void myMethod() {
myMethod(3);
}

void myMethod(int aParameter) {
// do something useful with aParameter
}


It cuts down on the amount of syntax, and Java was meant to be a simpler
language than C++.


By the way, you could also write the overloaded methods in C++, but there
are subtle differences between default parameters and overloaded methods --
that I don't quite grok, as I've never been a particularly proficient C++
programmer.

-- Adam Maass


 
Reply With Quote
 
axer
Guest
Posts: n/a
 
      02-04-2005
** Please, no debates, or speculations. We'll just waste your time and
my time. **

This is exactly why I asked for no speculation, because every Java
programmer I've asked this question always gives me incorrect logic.
As I'm sure you're aware of, your method is called overloading.
And the overloading method takes much more syntax then does using
default parameters. See example below:

I'm not interested in debating this issue, or speculation, because I
don't expect most Java programmers to fully understand the advantages
of default parameter arguments, nor how easy it is to implement into a
language.

That's why I'm only interested in any links or references to reputable
sites or book(s) that will DIRECTLY state the Java designers reason for
not including default parameter arguments in Java.

** Please, no debates, or speculations. We'll just waste your time and
my time. **


//The C/C++ way using defautl parameters
int ShowMessage(string MainMsg, string Title = "Info", int MessageType
= FooWarning, int MessageButtons = IDOK)
{
//Do message
}

The above is much easier to understand, easier to maintain, and easier
to find what you're looking for then the following Java overloaded
method:

int ShowMessage(string MainMsg, string Title, int MessageType, int
MessageButtons)
{
//Do message
}

int ShowMessage(string MainMsg, string Title, int MessageType)
{
return ShowMessage(MainMsg, Title, MessageType, IDOK);
}

int ShowMessage(string MainMsg, string Title)
{
return ShowMessage(MainMsg, Title, FooWarning, IDOK);
}

int ShowMessage(string MainMsg)
{
return ShowMessage(MainMsg, "Info", FooWarning, IDOK);
}

 
Reply With Quote
 
Antti S. Brax
Guest
Posts: n/a
 
      02-04-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote in comp.lang.java.programmer:
> ** Please, no debates, or speculations. We'll just waste your time and
> my time. **


Sorry, but Usenet does not work like that.

You throw us a question and we discuss it. If our discussion
answers your question or is helpful in some other way, that
is just a coincidence.

> This is exactly why I asked for no speculation, because every Java
> programmer I've asked this question always gives me incorrect logic.
> As I'm sure you're aware of, your method is called overloading.


So, how exactly do you spot the incorrect logic? Is it because
you already know the answer and are just trolling the group?
Is it because you have formed an opinion and the explanations
don't fit it? Maybe you should think about not being such an
harc core language fanatic?

> I'm not interested in debating this issue, or speculation, because I
> don't expect most Java programmers to fully understand the advantages
> of default parameter arguments, nor how easy it is to implement into a
> language.


Yeah, you're just trolling. And you're not even good at it.

--
Antti S. Brax Rullalautailu pitää lapset poissa ladulta
http://www.iki.fi/asb/ http://www.cs.helsinki.fi/u/abrax/hlb/
"Disconnect this cable to shorten, re-connect to lengthen."
-- Instructions on Logitech's USB mouse extension cord.
 
Reply With Quote
 
Thomas Schodt
Guest
Posts: n/a
 
      02-04-2005
Adam Maass wrote:
> I believe the OP means the C++ feature that looks like this:
>
> void myMethod(int aParameter = 3) {
> // do something useful with aParameter
> }


axer wrote:
> ** Please, no debates, or speculations. We'll just waste your time
> and my time. **


You do realise you are the one wasting other peoples time
by not making it clear what you are asking about.

Adam Maass made a guess.

You did not even bother quoting him and saying if that is what you mean.

Instead you harp on about how you think Usenet ought to work.

> That's why I'm only interested in any links or references to reputable
> sites or book(s) that will DIRECTLY state the Java designers reason
> for not including default parameter arguments in Java.


The Java designers did not consider the C++ style method default
argument feature worthwhile.

A better question would be
why did Stroustrup consider it worthwhile putting into C++?

Others have pondered over the severely limited virtues
of method default parameters features
<http://c2.com/cgi/wiki?EmulateKeywordAndDefaultParameters>


> ** Please, no debates, or speculations. We'll just waste your time
> and my time. **


You may opt to request of others what you would like them to do.
Others may opt to honour your request if they feel like it.
 
Reply With Quote
 
Adam Maass
Guest
Posts: n/a
 
      02-04-2005

"axer" <(E-Mail Removed)> wrote:
>
>
> //The C/C++ way using defautl parameters
> int ShowMessage(string MainMsg, string Title = "Info", int MessageType
> = FooWarning, int MessageButtons = IDOK)
> {
> //Do message
> }
>
> The above is much easier to understand, easier to maintain, and easier
> to find what you're looking for then the following Java overloaded
> method:
>
> int ShowMessage(string MainMsg, string Title, int MessageType, int
> MessageButtons)
> {
> //Do message
> }
>
> int ShowMessage(string MainMsg, string Title, int MessageType)
> {
> return ShowMessage(MainMsg, Title, MessageType, IDOK);
> }
>
> int ShowMessage(string MainMsg, string Title)
> {
> return ShowMessage(MainMsg, Title, FooWarning, IDOK);
> }
>
> int ShowMessage(string MainMsg)
> {
> return ShowMessage(MainMsg, "Info", FooWarning, IDOK);
> }
>


I don't disagree with you. And the client of the class in question would
have the same interface using either approach.

My reference to "less syntax" does not equate to "less verbose" or even
"more clear." I think the default parameter syntax was left out of Java
because -- from the perspective of a client of the class -- the same effect
can be achieved with method overloading, and method overloading was going to
be incorporated into Java anyway for other reasons, and the syntax for
default parameters in C++ just complicates the parsing rules of the language
for very little perceived benefit. Again, let me emphasize: from the
perspective of a client of the class, not an author or maintainer of the
class.

In addition, the way default parameters are implemented in (most flavors of)
C++ would be difficult to achieve in Java given its dynamic class loading
scheme. So even if default parameters had been carried over into Java from
C++, it is likely that the language spec would have required Java compilers
to treat any default parameter syntax as a shorthand for method overloading.

-- Adam Maass


 
Reply With Quote
 
axer
Guest
Posts: n/a
 
      02-04-2005
>>I don't disagree with you. And the client of the class in question
would
>>have the same interface using either approach.
>>My reference to "less syntax" does not equate to "less verbose" or

even
>>"more clear." I think the default parameter syntax was left out of

Java
>>because -- from the perspective of a client of the class -- the same

effect
>>can be achieved with method overloading, and method overloading was

going to
>>be incorporated into Java anyway for other reasons, and the syntax

for
>>default parameters in C++ just complicates the parsing rules of the

language
>>for very little perceived benefit. Again, let me emphasize: from the
>>perspective of a client of the class, not an author or maintainer of

the
>>class.


You're the first Java developer to come up with a reason that sounds
remotely possible and/or logical.


>>In addition, the way default parameters are implemented in (most

flavors of)
>>C++ would be difficult to achieve in Java given its dynamic class

loading
>>scheme. So even if default parameters had been carried over into Java

from
>>C++, it is likely that the language spec would have required Java

compilers
>>to treat any default parameter syntax as a shorthand for method

overloading.

What would be wrong with the Java compiler converting it to overloaded
methods?
I don't see what problems this would cause.
For example
http://java.sun.com/j2se/1.3/docs/ap...ptionPane.html
In the above link, if you look at the showMessageDialog method,
you'll see there are four overloaded methods.
Some or all of these methods could have been combined into one method
with default values.

If the compiler converted the following function into four separate
methods, how would that cause a problem?

int ShowMessage(string MainMsg, string Title = "Info", int MessageType
= FooWarning, int MessageButtons = IDOK);

Since it seems that no one really knows the official reason for this
feature not being included in the language, I guess I'll venture down
the debate road.
To be perfectly honest, my opinion is firm as to whether default
arguments are good for a language in GENERAL.

What I'm not sure of is whether default arguments are good for Java
specifically.

So what is unique about Java that would make it incompatible with
default parameter values, compare to other languages like C/C++?

 
Reply With Quote
 
alan@ljubljana.agtrz.com
Guest
Posts: n/a
 
      02-04-2005
On 2005-02-04, axer <(E-Mail Removed)> wrote:
>>>I don't disagree with you. And the client of the class in question would
>>>have the same interface using either approach.


>>>My reference to "less syntax" does not equate to "less verbose" or even
>>>"more clear." I think the default parameter syntax was left out of Java
>>>because -- from the perspective of a client of the class -- the same effect
>>>can be achieved with method overloading, and method overloading was going
>>>to be incorporated into Java anyway for other reasons, and the syntax for
>>>default parameters in C++ just complicates the parsing rules of the
>>>language for very little perceived benefit. Again, let me emphasize: from
>>>the perspective of a client of the class, not an author or maintainer of
>>>the class.


> You're the first Java developer to come up with a reason that sounds
> remotely possible and/or logical.


You are a goob.

> Since it seems that no one really knows the official reason for this
> feature not being included in the language, I guess I'll venture down
> the debate road.


How dare you waste my time! Do this! Do that!

--
Alan Gutierrez - (E-Mail Removed)
 
Reply With Quote
 
Chris Uppal
Guest
Posts: n/a
 
      02-04-2005
axer wrote:

> That's why I'm only interested in any links or references to reputable
> sites or book(s) that will DIRECTLY state the Java designers reason for
> not including default parameter arguments in Java.


There are a number of people hereabouts who are certainly as "reputable"
sources of information and insight as whatever sites or book(s) you are likely
to find. But your tone is not such as to encourage them to respond helpfully.

FWIW, I believe that default arguments are simply incompatible with Java
semantics. Its a matter of the differences between the name resolution schemes
in C++ and Java, but I'll leave you to look up the details yourself.

-- chris


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
SRC parameter not working in Mozilla when path is included wylbur37 Javascript 12 06-05-2004 09:14 AM
SRC parameter not working in Mozilla when path is included wylbur37 Firefox 1 06-05-2004 09:14 AM
SRC parameter not working in Mozilla when path is included wylbur37 Javascript 2 01-02-2004 02:52 PM
SRC parameter not working in Mozilla when path is included wylbur37 Firefox 1 01-02-2004 01:03 PM



Advertisments