Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Something important C++ is missing
Index -> Programming, C++ -> C++ Tutorials
Goto page Previous  1, 2, 3  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
wtd




PostPosted: Mon Jan 15, 2007 4:12 pm   Post subject: RE:Something important C++ is missing

Yes, Common Lisp is dynamically typed, so bar can be a value of any type (it is by default a string). However, this is not pertinent to the point the post was trying to make.
Sponsor
Sponsor
Sponsor
sponsor
Craige




PostPosted: Mon Jan 15, 2007 4:58 pm   Post subject: Re: Something important C++ is missing

Freakman @ Mon Jan 15, 2007 11:46 am wrote:
(I think) what wtd is trying to get across here is that, if you only have one parameter, and you set it to a default value, then there's really no point in calling that function when you have no parameters to pass it. Instead, you overload the function so that you can just call it without an argument. In Common Lisp however, you can call it with or without an argument and it will figure out if the argment is on the default value or not, and acts accordingly. It's basically a DRY issue.


Yeah, I'm sorry. I'm afraid I still don't get the point.
wtd




PostPosted: Mon Jan 15, 2007 5:10 pm   Post subject: RE:Something important C++ is missing

It's not just that it discerns whether or not the value supplied is the default value. It allows you, when writing the function body, to take into account whether or not the user supplied any value.
md




PostPosted: Mon Jan 15, 2007 7:46 pm   Post subject: RE:Something important C++ is missing

I have written code that does need to know if the callee provided the parameter or if it was the default. Fortunately my code can get away with doing the same things if the user explicitly passed the default as when the parameter wasn't passed.

But boy do I wish that I could see if a parameter was passed or if it's using the default.
Null




PostPosted: Mon Jan 15, 2007 10:09 pm   Post subject: Re: RE:Something important C++ is missing

wtd @ Mon Jan 15, 2007 5:10 pm wrote:
It's not just that it discerns whether or not the value supplied is the default value. It allows you, when writing the function body, to take into account whether or not the user supplied any value.


Could you please provide a practical piece of code where knowing whether there was a value passed or not is essential? Smile

I'm curious, because I'm having trouble thinking of one on my own.
wtd




PostPosted: Mon Jan 15, 2007 10:20 pm   Post subject: RE:Something important C++ is missing

Think of any time in C++ when you would write:

code:
some_type foo(some_other_type arg)
{
  // ...
}

some_type foo()
{
   // Not just:
   // return foo(some_default_value);
}


Where such a pattern is employed, the bodies are clearly taking different actions based on whether or not the user provides a value. Otherwise, a default parameter value would be employed.
ericfourfour




PostPosted: Mon Jan 15, 2007 10:20 pm   Post subject: RE:Something important C++ is missing

Maybe when using constructors, you want to have multiple ways of initializing the object.
md




PostPosted: Tue Jan 16, 2007 1:43 am   Post subject: RE:Something important C++ is missing

How about this: you're sending a UDP packet over a socket. The socket is bound to a port but you can send on any port. So you want to allow the user to specify a port to send on, and use the bound port if they don't. You either have to write a function which takes a port AND a function which doesn't and passes the bound port number to the first function; or find some default value which isn't a port (zero in this case).

A real world example.
Sponsor
Sponsor
Sponsor
sponsor
abcdefghijklmnopqrstuvwxy




PostPosted: Wed Jan 17, 2007 2:48 am   Post subject: RE:Something important C++ is missing

So that fact that you can easily solve the aforementioned issue with function overloading makes it detrimental to the integrity of the C++ language? Forgive me, but if the user supplies a value that equals the default value there would be no reason to test if the user supplied the default or not.
md




PostPosted: Wed Jan 17, 2007 12:55 pm   Post subject: RE:Something important C++ is missing

No, the fact that one must resort to function overloading to know if the parameter is the default or if it was actually passed is the weakness. Not detrimental to the integrity of the language; but it's a big important feature that is missing and would be great to have.

And yes, usually if the user provides the same value as the default it doesn't matter. However I'm sure it's possible to think of a case where it would matter.
abcdefghijklmnopqrstuvwxy




PostPosted: Wed Jan 17, 2007 11:50 pm   Post subject: Re: Something important C++ is missing

why is function overloading so bad?
wtd




PostPosted: Thu Jan 18, 2007 12:41 am   Post subject: RE:Something important C++ is missing

It's not.
avok23




PostPosted: Sun May 04, 2008 3:43 am   Post subject: Re: RE:Something important C++ is missing

code:
some_type foo(some_other_type arg = NULL)
{
  if(args == NULL)
  {
     //do default
  }
  else
  {}
}


Very Happy

BTW c++ is the greatest language ever
wtd




PostPosted: Sun May 04, 2008 11:22 am   Post subject: RE:Something important C++ is missing

What if the programmer supplied a value, but that value was NULL?
avok23




PostPosted: Mon May 05, 2008 8:48 pm   Post subject: Re: RE:Something important C++ is missing

wtd @ Sun May 04, 2008 11:22 am wrote:
What if the programmer supplied a value, but that value was NULL?


i just wonder why any one would do that. What kind of function would require that?
Display posts from previous:   
   Index -> Programming, C++ -> C++ Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 3  [ 34 Posts ]
Goto page Previous  1, 2, 3  Next
Jump to:   


Style:  
Search: