[Phpmyadmin-devel] Maximum length of variable names

Hugues Peccatte hugues.peccatte at gmail.com
Mon Jan 6 19:14:39 CET 2014


Hi,

2014/1/6 Chanaka Dharmarathna <pe.chanaka.ck at gmail.com>

>
>
>  >> I'm aware that I'm opening a can of worms, but can we discuss PHPMD
>> rules?
>> >
>> > I think those were never actually discussed, we just run then in
>> > Jenkins. So I think it's good idea to discuss coding style beyond
>> > indentation and whitespaces.
>> >
>> >> In particular, I find that to obey the maximum variable name (20
>> >> characters) rule, one has to sometimes abbreviate at the expanse of
>> clarity.
>> >
>> > I think this is quite connected to line length as well. In case you
>> > have longer variable names and stick with current line length, the code
>> > will be a bit harder to read due to necessary wrapping, for example:
>> >
>> >
>> https://github.com/phpmyadmin/phpmyadmin/blob/master/libraries/browse_foreigners.lib.php#L152
>>
>
> I think the length of a variable name we should use is depend on variable
> scope and complexity of the code segment. Less complexity code segment may
> have shorten variable name while more complex code segment will have
> lengthy variable names. Same for the scope as well. I prefer to have bit
> lengthy variable since it will self describe the code even without the
> comments.
>
> In case we care on the length, we can use comments on a variable
> initializing point, which describe the shorten variable clearly. As well as
> using camel case naming convention will save us from additional underscores
> ($getEntryById < $get_entry_by_id)
>
> But as a standard we better have a limitation on the length of a variable
> name. But I think we better keep the limit more than 20 (what about 25 ?)
>

I agree. But is it possible to change the allowed length ?
Here we are talking about PMD (
http://ci.phpmyadmin.net/job/phpMyAdmin/910/pmdResult/type.811406648/), so
I believe that we can't…


>
>
>>
>> I see two possibilities here:
>> - abbreviate variable names (would make them even more difficult to
>> understand)
>> - improve the logic (I'll work on this case :)  )
>>
>> >
>> > Looking at current long variable names, I see following patterns:
>> >
>> > - pma prefix, is that really needed? [1]
>> No.
>>
>> >
>> > - return values from function called $something_somewhere_html, using
>> >   just $result might be even better to understand in this context [2]
>> Agreed, when it's inside a function.
>>
>> >
>> > - some variables still being used as globals, thus needing to provide
>> >   too much context in their names [3]
>> Usually a hint that this code segment needs refactoring.
>> >
>> > - some probably legitimate usages of long name [4]
>> Agreed.
>>
>> >
>> > [1]:
>> https://github.com/phpmyadmin/phpmyadmin/blob/master/view_create.php#L95
>> > [2]:
>> https://github.com/phpmyadmin/phpmyadmin/blob/master/libraries/DisplayResults.class.php#L5203
>> > [3]:
>> https://github.com/phpmyadmin/phpmyadmin/blob/master/libraries/mysql_charsets.inc.php#L17
>> > [4]:
>> https://github.com/phpmyadmin/phpmyadmin/blob/master/libraries/DisplayResults.class.php#L2779
>>
>
> --
> Chanaka Dharmarathna
> *Virtusa (Pvt) Ltd. | **Sri Lanka*
>
>
Hugues.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.phpmyadmin.net/pipermail/developers/attachments/20140106/98948ff5/attachment.html>


More information about the Developers mailing list