You are viewing a plain text version of this content. The canonical link for it is here.
Posted to zeta-dev@incubator.apache.org by Jerome Renard <je...@gmail.com> on 2011/03/07 18:00:19 UTC
[zeta-dev] Naming convention : *List variables
Hi there,
I would propose a small addition to the naming conventions.
A list of recommended names is already provided in
http://incubator.apache.org/zetacomponents/community/implementation.html#general-guidelines
however there is nothing proposed for variables like arrays.
As an example you can compare the two following snippets
Without "List" variable:
$rows = fetchSomeRows();
foreach($rows as row)
[....]
With "List' variable:
$rowList = fetchSomeRows();
foreach($rowList as $row)
[....]
The rationale for such variable names is that adds a bit more
semantics on what the variable
is supposed to contains. It should also help to avoid typos which
makes debugging harder.
What do you think ?
:)
--
Jérôme Renard
http://39web.fr | http://jrenard.info | http://twitter.com/jeromerenard
Re: [zeta-dev] Naming convention : *List variables
Posted by Derick Rethans <de...@apache.org>.
On Mon, 7 Mar 2011, Jerome Renard wrote:
> I would propose a small addition to the naming conventions.
>
> A list of recommended names is already provided in
> http://incubator.apache.org/zetacomponents/community/implementation.html#general-guidelines
> however there is nothing proposed for variables like arrays.
>
> As an example you can compare the two following snippets
>
> Without "List" variable:
> $rows = fetchSomeRows();
> foreach($rows as row)
> [....]
>
> With "List' variable:
> $rowList = fetchSomeRows();
> foreach($rowList as $row)
> [....]
>
> The rationale for such variable names is that adds a bit more
> semantics on what the variable
> is supposed to contains. It should also help to avoid typos which
> makes debugging harder.
>
> What do you think ?
I don't think we should name variables according what type they are.
We'll end up with $iCounter etc as well. $rows (plural) is IMO perfectly
acceptable.
cheers,
Derick
--
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug
Re: [zeta-dev] Naming convention : *List variables
Posted by Maxime Thomas <ma...@gmail.com>.
2011/3/7 Jerome Renard <je...@gmail.com>
> Derick, Patrick,
>
> On Mon, Mar 7, 2011 at 7:09 PM, Patrick ALLAERT
> <pa...@gmail.com> wrote:
> > 2011/3/7 Jerome Renard <je...@gmail.com>:
> [...]
> >
> > There is nothing wrong being explicit about the content of the
> > variable, but I would refrain from using types like "Array", "List",
> > "Integer",...
>
> Maybe I have not been clear enough.
>
> The point is not to name a variable acording to its type for ints,
> floats etc, etc.
>
> The point is to provide a visual/semantic help for arrays (or
> hastables) *only* by suffixing them.
> Using a variable in its plural form might not be ideal for some
> people, this is what I am
> trying to adress with this idea, which maybe is a stupid one.
>
> The rest (int and others) remains unchanged.
>
> :)
>
> --
> Jérôme Renard
> http://39web.fr | http://jrenard.info | http://twitter.com/jeromerenard
>
Ok, so if I understand it well : you put List after variables that you will
use in foreach.
Do we put other variables types in foreach than arrays ?
For the name rules for variables, I personnaly used the "_id" suffix
to semantically design a integer variable, the "s" suffix for lists (it
could be also more gramatically based rules : child / children) and by
default vars are strings.
For small treatments, not meaningful, I prefer to use "anonymous" variable
names like $i, $j, $k, $v... It could be for example, a generic function
that processes an array.
--
Maxime
maxime.thomas@wascou.org | www.wascou.org | http://twitter.com/wascou
Re: [zeta-dev] Naming convention : *List variables
Posted by Jerome Renard <je...@gmail.com>.
Bertrand,
On Mon, Mar 21, 2011 at 8:07 PM, Bertrand Dunogier <bd...@ez.no> wrote:
> On 21 March 2011 19:26, Jerome Renard <je...@gmail.com> wrote:
>>
>> 19:20 jerome@gimli/private/tmp/ezpublish% grep -nR "[a-z]List" kernel
>> lib | wc -l
>> 6012
>
> I have given my opinion, not the 10 past years authors' :-)
Yeah I know, that was just to tease you a bit ;)
> There are indeed a few situations where I believe a word makes much more
> sense than a simple 's', but not generally speaking.
>>
>> Anyway, let's say my idea was stupid/useless/not relevant/other and
>> close this thread.
>
> Sorry if my answer was irrelevant and made you feel that way... I thought I
> had merely given my view about the proposal you had made.
Ho, everything is OK. The discussion showed my idea was not as good as I
initially thought. I would just avoid losing time on this (bad) idea and focus
and the rest in order to get a release.
Cheers :)
--
Jérôme Renard
http://39web.fr | http://jrenard.info | http://twitter.com/jeromerenard
Re: [zeta-dev] Naming convention : *List variables
Posted by Bertrand Dunogier <bd...@ez.no>.
On 21 March 2011 19:26, Jerome Renard <je...@gmail.com> wrote:
> 19:20 jerome@gimli/private/tmp/ezpublish% grep -nR "[a-z]List" kernel
> lib | wc -l
> 6012
>
I have given my opinion, not the 10 past years authors' :-)
There are indeed a few situations where I believe a word makes much more
sense than a simple 's', but not generally speaking.
Anyway, let's say my idea was stupid/useless/not relevant/other and
> close this thread.
>
Sorry if my answer was irrelevant and made you feel that way... I thought I
had merely given my view about the proposal you had made.
--
Bertrand Dunogier
Re: [zeta-dev] Naming convention : *List variables
Posted by Jerome Renard <je...@gmail.com>.
Hello,
On Mon, Mar 21, 2011 at 4:44 PM, Bertrand Dunogier <bd...@ez.no> wrote:
> Jerome,
>
> On 18 March 2011 12:03, Tobias Schlitt <to...@schlitt.info> wrote:
>>
>> Hmm, I generally don't like to change my coding habbits and by now we
>> usually use the plural form for stuff like $rows, $elements and friends.
>> This generally indicates that you have a collection of something, which
>> you can iterate over or access dedicatedly. I find it quite clear and
>> intuitive.
>
> I have to agree with this. Plural perfectly fits here, imho, and if "some"
> can't cope with that, it means their english ain't good enuf' and they
> should improve it :-)
19:20 jerome@gimli/private/tmp/ezpublish% grep -nR "[a-z]List" kernel
lib | wc -l
6012
Anyway, let's say my idea was stupid/useless/not relevant/other and
close this thread.
Otherwise I have the feeling it is going to last for quite a while
without relevant results.
:)
--
Jérôme Renard
http://39web.fr | http://jrenard.info | http://twitter.com/jeromerenard
Re: [zeta-dev] Naming convention : *List variables
Posted by Henri Bergius <be...@apache.org>.
On Mon, Mar 21, 2011 at 5:44 PM, Bertrand Dunogier <bd...@ez.no> wrote:
> I have to agree with this. Plural perfectly fits here, imho, and if "some"
> can't cope with that, it means their english ain't good enuf' and they
> should improve it :-)
I've seen people argue that even better than pluralization is using
variable names like listOfSomething, as just the 's' may be easy to
overlook.
> Bertrand Dunogier
/Henri
Re: [zeta-dev] Naming convention : *List variables
Posted by Gaetano Giunta <gi...@gmail.com>.
Bertrand Dunogier wrote:
> ve to agree with this. Plural perfectly fits here, imho, and if "some"
> can't cope with that, it means their english ain't good enuf' and they
> should improve
nah.
what I want is variable names that encode type, visibility, scope and weather conditions
;-)
Re: [zeta-dev] Naming convention : *List variables
Posted by Bertrand Dunogier <bd...@ez.no>.
Jerome,
On 18 March 2011 12:03, Tobias Schlitt <to...@schlitt.info> wrote:
> Hmm, I generally don't like to change my coding habbits and by now we
> usually use the plural form for stuff like $rows, $elements and friends.
> This generally indicates that you have a collection of something, which
> you can iterate over or access dedicatedly. I find it quite clear and
> intuitive.
>
I have to agree with this. Plural perfectly fits here, imho, and if "some"
can't cope with that, it means their english ain't good enuf' and they
should improve it :-)
--
Bertrand Dunogier
Lead Engineer Extensions
eZ systems
Re: [zeta-dev] Naming convention : *List variables
Posted by Tobias Schlitt <to...@schlitt.info>.
Hi,
On 03/07/2011 07:19 PM, Jerome Renard wrote:
> On Mon, Mar 7, 2011 at 7:09 PM, Patrick ALLAERT
> <pa...@gmail.com> wrote:
>> 2011/3/7 Jerome Renard <je...@gmail.com>:
>> There is nothing wrong being explicit about the content of the
>> variable, but I would refrain from using types like "Array", "List",
>> "Integer",...
> Maybe I have not been clear enough.
>
> The point is not to name a variable acording to its type for ints,
> floats etc, etc.
>
> The point is to provide a visual/semantic help for arrays (or
> hastables) *only* by suffixing them.
> Using a variable in its plural form might not be ideal for some
> people, this is what I am
> trying to adress with this idea, which maybe is a stupid one.
>
> The rest (int and others) remains unchanged.
Hmm, I generally don't like to change my coding habbits and by now we
usually use the plural form for stuff like $rows, $elements and friends.
This generally indicates that you have a collection of something, which
you can iterate over or access dedicatedly. I find it quite clear and
intuitive.
In addition, I don't see a point in changing this now and creating a
mess in the code due to the resulting mixture of both namings.
Regards,
Toby
--
Tobias Schlitt http://schlitt.info GPG Key: 0xC462BC14
Want to hire me? Need quality assurance? http://qafoo.com
eZ Components are Zeta Components now! http://bit.ly/9S7zbn
Re: [zeta-dev] Naming convention : *List variables
Posted by Jerome Renard <je...@gmail.com>.
Derick, Patrick,
On Mon, Mar 7, 2011 at 7:09 PM, Patrick ALLAERT
<pa...@gmail.com> wrote:
> 2011/3/7 Jerome Renard <je...@gmail.com>:
[...]
>
> There is nothing wrong being explicit about the content of the
> variable, but I would refrain from using types like "Array", "List",
> "Integer",...
Maybe I have not been clear enough.
The point is not to name a variable acording to its type for ints,
floats etc, etc.
The point is to provide a visual/semantic help for arrays (or
hastables) *only* by suffixing them.
Using a variable in its plural form might not be ideal for some
people, this is what I am
trying to adress with this idea, which maybe is a stupid one.
The rest (int and others) remains unchanged.
:)
--
Jérôme Renard
http://39web.fr | http://jrenard.info | http://twitter.com/jeromerenard
Re: [zeta-dev] Naming convention : *List variables
Posted by Patrick ALLAERT <pa...@gmail.com>.
2011/3/7 Jerome Renard <je...@gmail.com>:
> Hi there,
>
> I would propose a small addition to the naming conventions.
>
> A list of recommended names is already provided in
> http://incubator.apache.org/zetacomponents/community/implementation.html#general-guidelines
> however there is nothing proposed for variables like arrays.
>
> As an example you can compare the two following snippets
>
> Without "List" variable:
> $rows = fetchSomeRows();
> foreach($rows as row)
> [....]
>
> With "List' variable:
> $rowList = fetchSomeRows();
> foreach($rowList as $row)
> [....]
>
> The rationale for such variable names is that adds a bit more
> semantics on what the variable
> is supposed to contains. It should also help to avoid typos which
> makes debugging harder.
>
> What do you think ?
Regarding your example, I generally prefer using the plural form or
"$row" being "$rows" than adding extra semantics.
Being too verbose sometimes leads to:
$messageString = "Hello World";
$ultimateAnwserInteger = 42;
instead of:
$message = "Hello World";
$ultimateAnwser = 42;
There is nothing wrong being explicit about the content of the
variable, but I would refrain from using types like "Array", "List",
"Integer",...
My 2 cents,
Patrick