473,395 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Default Arguments

Default Arguments: what's the general consensus about them? To give an
example, so we're all on the same page, this is the syntax I'm talking
about:

function foo($bar = "some value"){
}
So, in the past when I was programming with PHP a lot, I found myself
using default arguments more and more because they were so convenient.
But in the back of my mind, something about them seemed
somewhat...sloppy. I've never had the privilege of working on a
project quite large enough for architectural weaknesses to really show
their strain, so I'd like to pose this question to other minds, to see
if any of you have input about this syntactical tool.

Thanks!
Jul 18 '08 #1
3 1238

<bu*************@gmail.comwrote in message
news:57**********************************@25g2000h sx.googlegroups.com...
Default Arguments: what's the general consensus about them? To give an
example, so we're all on the same page, this is the syntax I'm talking
about:

function foo($bar = "some value"){
}
So, in the past when I was programming with PHP a lot, I found myself
using default arguments more and more because they were so convenient.
But in the back of my mind, something about them seemed
somewhat...sloppy.
misconception major...number 1
I've never had the privilege of working on a
project quite large enough for architectural weaknesses to really show
their strain, so I'd like to pose this question to other minds, to see
if any of you have input about this syntactical tool.
it's a convenience. if i have a function that has umphteen args and they
don't have default values, i have to have an ugly mess of '', '' or null,
null, null or whatever. it is much cleaner only supplying arguments that are
ACTUALLY needed. it's stupidity not to.
Jul 18 '08 #2
bu*************@gmail.com wrote:
Default Arguments: what's the general consensus about them? To give an
example, so we're all on the same page, this is the syntax I'm talking
about:

function foo($bar = "some value"){
}
So, in the past when I was programming with PHP a lot, I found myself
using default arguments more and more because they were so convenient.
But in the back of my mind, something about them seemed
somewhat...sloppy. I've never had the privilege of working on a
project quite large enough for architectural weaknesses to really show
their strain, so I'd like to pose this question to other minds, to see
if any of you have input about this syntactical tool.

Thanks!
I think default arguments are fine if you have a specific default
argument to pass. It just helps keep the code cleaner.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jul 18 '08 #3

"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:g5**********@registered.motzarella.org...
bu*************@gmail.com wrote:
>Default Arguments: what's the general consensus about them? To give an
example, so we're all on the same page, this is the syntax I'm talking
about:

function foo($bar = "some value"){
}
So, in the past when I was programming with PHP a lot, I found myself
using default arguments more and more because they were so convenient.
But in the back of my mind, something about them seemed
somewhat...sloppy. I've never had the privilege of working on a
project quite large enough for architectural weaknesses to really show
their strain, so I'd like to pose this question to other minds, to see
if any of you have input about this syntactical tool.

Thanks!

I think default arguments are fine if you have a specific default argument
to pass. It just helps keep the code cleaner.
I just wish php supported named arguments too.
Jul 19 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

46
by: J.R. | last post by:
Hi folks, The python can only support passing value in function call (right?), I'm wondering how to effectively pass a large parameter, such as a large list or dictionary? It could achieved...
14
by: Edward Diener | last post by:
In the tutorial on functions there are sections on default arguments and keyword arguments, yet I don't see the syntactic difference between them. For default arguments the tutorial shows: def...
8
by: Agent Mulder | last post by:
Hi group, I want to know why this doesn't work void f(int a=0,int b=1,int c=2){} int main() { f(); //OK f(1); //OK f(1,2); //OK f(1,2,3); //OK
12
by: earl | last post by:
class temp { public: temp(); foo(char, char, char*); private: char matrix; }; temp::foo(char p, char o, char m = matrix )
18
by: Dan Cernat | last post by:
Hi there, A few threads I had a little chat about default values. I am starting this thread because I want to hear more opinions about the default values of function parameters. Some say they...
18
by: Matt | last post by:
I try to compare the default constructor in Java and C++. In C++, a default constructor has one of the two meansings 1) a constructor has ZERO parameter Student() { //etc... } 2) a...
4
by: aling | last post by:
What's the rule of default argument of function in C++? I found that the default argument of function could not necessary be a constant value. Is it true? Previously I thought that the default...
10
by: Alan G Isaac | last post by:
My class MyClass reuses many default parameters with a small number of changes in each instance. For various reasons I decided to put all the parameters in a separate Params class, instances of...
12
by: claudiu | last post by:
Hi, I'll go straight to the first question. Why does the code below compile? void f(int i = 0); int main() { (&f)();
35
by: bukzor | last post by:
I've found some bizzare behavior when using mutable values (lists, dicts, etc) as the default argument of a function. I want to get the community's feedback on this. It's easiest to explain with...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.