Jump to content

[Grump from a beginner] Function Names


elnaz1010

Recommended Posts

hi

i had some knowledge with php and asp, but im not an advanced one. recently i decide to learn php in more depth. because i like open source and i see a lot of fans trying to make it better than before.

and im reading a book for it.

something that bother my mind is function names.

i want to know why functions (not all of them though) have no meaning full names in them?

for example if i want to work with files, i have: fread(), readfile(), fpassthru(),  file() functions. and as you see none of them tells you what they do if you are not familiar with them.

also for naming, some of them use "file" (like: readfile, file)  and some of them use "f" as abbreviations (like: fread(), fpassthru()) .

 

also for reading from file i have: fgets(), fgetss(), fgetcsv(). again, name tells you nothing. for example if you see fgetss() for the first time, you cant say what is the difference between fgets() or fgetss().

 

another problem i see in functions is name convention. for example we have file_exist() and filesize(). why in some function there is an underline between names and in some of them there isn't?

if i know some language like c or delphi, i expect when i use filesize(), there is a function name fileexist() or vice versa.

 

also i noticed that php still haven't got unicode support with asp had it a long time ago.

 

i know it probably needs huge code to be implemented, so its not a big deal in my mind if php haven't got it since.

but names of function is a simple thing to fix and it should be straightforward for those who are going to learn php.

 

as far aas i know, asp have a better naming and almost all of them gives you some idea about what they do.

 

i was a fan of php and when we debate with my friend, i was in php side and against asp.

 

the next thing that i couldnt figure out is new feature, i looked in changelog of php 5.3, and i see its now support for closures ans true anonymous functions, i know it has its use, but lets face it, doesnt something like this make our code much less readable?

i see an example about it in wikipedia:

function getAdder($x)
{
    return function ($y) use ($x) {
        return $x + $y;
    };
}

$adder = getAdder(;
echo $adder(2); // prints "10"

but these things that i see are bothering me, can someone please correct me if im wrong?

i hope i could make my mean clear.

Link to comment
Share on other sites

fread(), readfile(), fpassthru()

 

PHP is based heavily off of C and will inherit many of the syntax styles and structures/function names of it. I coded with VB.NET for a while and it's incredibly clear the difference in naming conventions, but to an intermediate programmer 'fopen' is much more memorable and efficient than open_a_file_with_this_function(), Albeit an alias function named file_get_contents and file_put_contents exist.

 

also i noticed that php still haven't got unicode support with asp had it a long time ago.

 

It has unicode support, Such as a wide array of multibyte functions, Just no support over ASCII for functions and declarations.

 

for example we have file_exist() and filesize()

 

Functions are grouped together usually, such as is_array, is_object, is_string, file_exists, file_put_contents (etc etc..) I don't think the need for a 'perfect uniform' syntax is required, it is only but your opinion on this matter, as you may have many complaints about C's constructs. This should be learned.

 

C syntax

 

I would get used to the syntax of these languages, as they are much much more different than ASP-OO style programming.

Link to comment
Share on other sites

fread(), readfile(), fpassthru()

 

PHP is based heavily off of C and will inherit many of the syntax styles and structures/function names of it. I coded with VB.NET for a while and it's incredibly clear the difference in naming conventions, but to an intermediet programmer 'fopen' is much more memorable and efficient than open_a_file_with_this_function(), Albeit an alias function named file_get_contents and file_put_contents exist.

 

C syntax

 

I would get used to the syntax of these languages, as they are much much more different than ASP-OO style programming.

yes i agree with you, fread is much memorable, but why some of them use readfile, and some use fread?

i think its not memorable at all. they all should use same naming convention to be easy memorable.

 

and about C, yes it is heavily on C syntax, but php should not have filesize because C have no filedize at all as far az i know, so if we want to be like C, we should have file_size(). because C use underline in such a functions. example is file_exist()

Link to comment
Share on other sites

I'm tired and wish not to argue about you for syntax except to say it does not matter. If something as simple as an underline in a function name that was defined for backwards compatibility is a problem for you, then maybe you should stick to a much simpler programming language.

 

You should take a look at http://php.net/quickref.php to see what you're getting into, if you scroll down to 'filesize' then you will notice many functions like it, similarily named and similar in function apt to the language.

Link to comment
Share on other sites

I don't think the need for a 'perfect uniform' syntax is required, it is only but your opinion on this matter, as you may have many complaints about C's constructs. This should be learned.

i heavily disagree with you, all i read in programing source in computer science, they say one parameter for a good language is a good naming convention.

and for a language like php, i think its good to have a perfect naming convetion, i mean come on, its not hard to implement a good name for a function.

if you say we should support backward compatibility, i say at least make these bad names an old feature, so they will be fixed in next versions. just like globals removed.

74321244.jpg

Naming Convention

 

anyway thanks for your reply, i appreciate it,

i just wants to say my opinion.

regards

Link to comment
Share on other sites

I don't think the need for a 'perfect uniform' syntax is required, it is only but your opinion on this matter, as you may have many complaints about C's constructs. This should be learned.

i heavily disagree with you, all i read in programing source in computer science, they say one parameter for a good language is a good naming convention.

and for a language like php, i think its good to have a perfect naming convetion, i mean come on, its not hard to implement a good name for a function.

if you say we should support backward compatibility, i say at least make these bad names an old feature, so they will be fixed in next versions. just like globals disabled.

74321244.jpg

and now its planed to be removed:

61845647.jpg

 

and about naming convention:

Naming Convention

 

anyway thanks for your reply, i appreciate it,

i just wants to say my opinion.

regards

 

argh... im ruining the forum structure, reported my self to get fixed.

sorry anyways :(

 

Report Received: Status:  The forum and its structure are completely screwed now,  because of you and your quoting!

Link to comment
Share on other sites

That's one of the PHP's features I do not like very much: it wants to be backward compatible at all costs. And given that on it earliest days several choices were taken without giving much thought (or so it seems), the cost is pretty high.

You're worried about inconsistent function naming... What will you say about argument order? Sometimes stack comes boefore needle, sometimes the other way round.

Link to comment
Share on other sites

That's one of the PHP's features I do not like very much: it wants to be backward compatible at all costs. And given that on it earliest days several choices were taken without giving much thought (or so it seems), the cost is pretty high.

You're worried about inconsistent function naming... What will you say about argument order? Sometimes stack comes boefore needle, sometimes the other way round.

 

http://tnx.nl/php.html

 

It's just the way it will be. There's some more insight into your problems with PHP (Atleast compared to PERL), but there ARE also reasons why it is good.

 

http://www.webpronews.com/expertarticles/2005/12/22/asp-vs-php (business perspective)

http://pthree.org/2006/01/11/why-php-is-better-than-aspaspnet/ :P

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.