php-general Digest 3 Jun 2012 21:10:13 -0000 Issue 7839

Topics (messages 318115 through 318121):

Re: Function size
        318115 by: Tim Streater
        318116 by: Tony Marston

Re: Using default argument values in the middle of the argument list
        318117 by: oliver gondža
        318120 by: Matijn Woudt

Re: cyberweaponry
        318118 by: Tedd Sperling
        318119 by: Daniel P. Brown

disabled cookies
        318121 by: Al

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On 03 Jun 2012 at 10:02, Tony Marston <tonymars...@hotmail.com> wrote: 

> "tamouse mailing lists"  wrote in message
> news:cahuc_t__sw-_yhrw4n4uqr-fa46+cebunzgehboaatrafla...@mail.gmail.com...

>> There is a point: if you are unfamiliar with code, wading through
>> screens and screens of a function to find things like block
>> beginning/ends makes for difficult time finding places where changes
>> need to be made.
>
> I *never* have huge numbers of lines between a block beginning and end. Even
> if I did my IDE can quickly find the other end of the block for me.

E.g. TextWrangler does this easily enough: just double-click immediately after 
an opening brace, and everything is highlighted to the closing brace.

>>> - all those functions should be arranged in alphabetical order within
>>> their containing file - having them in a random sequence makes it
>>> difficult to find the one you want.
>>
>> Also correct; this is a key point in making sure your scripts are
>> maintainable.
>
> Ah-ha! So someone agrees with me on that point after all.

+1

>>> - when browsing through the code you have to keep jumping to another
>>> function, and then returning to where you came from.
>>>
>>> I don't know about you, but I would rather use the scroll wheel on my
>>> mouse
>>> than keep jumping from one position in the file to another.
>>
>> May I suggest an editor/IDE that lets you navigate to functions directly,
>> then?
>
> I am *NOT* going to change my IDE just to suit *YOUR* preferences.

TW provided a popup list of your functions. It still helps to have them in 
alpha order though, for ease of navigation in the popup list.

[snip arguments]

I write functions to do specific things. E.g. I have a function (actually in 
JavaScript) called switchTab() which switches from one user view to another. 
It's just over 200 lines long and is mostly a giant case statement - and it's 
already loaded with function calls. I suppose I could break it up into five 
separate functions, more or less one for each case value, but then I'd have 
lots of unimportant local variables to pass around as argument values, and, 
what's worse, lots of unimportant functions cluttering the place up.

--
Cheers  --  Tim

--- End Message ---
--- Begin Message ---
"Tim Streater"  wrote in message news:d0.7c.45755.25a3b...@pb1.pair.com...

On 03 Jun 2012 at 10:02, Tony Marston <tonymars...@hotmail.com> wrote:

"tamouse mailing lists"  wrote in message
news:cahuc_t__sw-_yhrw4n4uqr-fa46+cebunzgehboaatrafla...@mail.gmail.com...

There is a point: if you are unfamiliar with code, wading through
screens and screens of a function to find things like block
beginning/ends makes for difficult time finding places where changes
need to be made.

I *never* have huge numbers of lines between a block beginning and end. Even
if I did my IDE can quickly find the other end of the block for me.

E.g. TextWrangler does this easily enough: just double-click immediately after an opening brace, and everything is highlighted to the closing brace.

- all those functions should be arranged in alphabetical order within
their containing file - having them in a random sequence makes it
difficult to find the one you want.

Also correct; this is a key point in making sure your scripts are
maintainable.

Ah-ha! So someone agrees with me on that point after all.

+1

- when browsing through the code you have to keep jumping to another
function, and then returning to where you came from.

I don't know about you, but I would rather use the scroll wheel on my
mouse
than keep jumping from one position in the file to another.

May I suggest an editor/IDE that lets you navigate to functions directly,
then?

I am *NOT* going to change my IDE just to suit *YOUR* preferences.

TW provided a popup list of your functions. It still helps to have them in alpha order though, for ease of navigation in the popup list.

[snip arguments]

I write functions to do specific things. E.g. I have a function (actually in JavaScript) called switchTab() which switches from one user view to another. It's just over 200 lines long and is mostly a giant case statement - and it's already loaded with function calls. I suppose I could break it up into five separate functions, more or less one for each case value, but then I'd have lots of unimportant local variables to pass around as argument values, and, what's worse, lots of unimportant functions cluttering the place up.

Exactly! That's one good reason *NOT* to break up a large function into artificially small pieces. You generate a lot of useless code just to handle the small pieces, and wading through lots of useless code makes it less readable. In my opinion it takes less effort to use the scroll wheel on my mouse than it does to jump/return from different parts of the file. There are times when it makes sense to split a large function into smaller pieces, but I'm afraid that doing so for no other reason than to satisfy someone's personal line limit is just not good enough.

--
Tony Marston

http://www.tonymarston.net
http://www.radicore.org
--- End Message ---
--- Begin Message ---
On Sat, 02 Jun 2012 21:35:28 +0200, Matijn Woudt <tijn...@gmail.com> wrote:

It does not state it works only at the end of the list, it states that
it only makes sense to use it at the end of the argument list to be
able to call the function with less arguments. In case you want to use
it as suggested in [2], you can use it anywhere. You can rely on that
in any PHP version from 5 upwards, just because version 4 doesn't
support type hinting at all.

- Matijn

[2] http://php.net/manual/en/language.oop5.typehinting.php

Wow that's great. Just to be sure are we talking about functions it's default arguments precedes its non-default arguments:

function f ( Classname $a = null, Classname $b ) { ... }

I believe it should be clearly stated in documentation that it is possible for several reasons.

- I have never thought of using type hints and default arguments this way until I found it by accident. - I have never seen someone else using it (I've just search installed PEAR packages, codebase of Symphony2, Zend2 and several others and found *one* function definition taking advantage of this*). - As far as i know other languages that support default argument values allow specifying default arguments only for rightmost function arguments. - As far as i know the only part of documentation that illustrates function declarations having default argument preceding non-default arguments is the one titled: "Incorrect usage of default function arguments" in http://www.php.net/manual/en/functions.arguments.php.

I just wanted to be sure this is haw it is supposed to be used.

* DibiColumnInfo::__construct(IDibiReflector $reflector = NULL, array $info) in https://github.com/dg/dibi/blob/master/dibi/libs/DibiDatabaseInfo.php#L458

-- Oliver

--- End Message ---
--- Begin Message ---
On Sun, Jun 3, 2012 at 4:48 PM, oliver gondža <ogon...@gmail.com> wrote:
> On Sat, 02 Jun 2012 21:35:28 +0200, Matijn Woudt <tijn...@gmail.com> wrote:
>
>> It does not state it works only at the end of the list, it states that
>> it only makes sense to use it at the end of the argument list to be
>> able to call the function with less arguments. In case you want to use
>> it as suggested in [2], you can use it anywhere. You can rely on that
>> in any PHP version from 5 upwards, just because version 4 doesn't
>> support type hinting at all.
>>
>> - Matijn
>>
>> [2] http://php.net/manual/en/language.oop5.typehinting.php
>
>
> Wow that's great. Just to be sure are we talking about functions it's
> default arguments precedes its non-default arguments:
>
> function f ( Classname $a = null, Classname $b ) { ... }
>
> I believe it should be clearly stated in documentation that it is possible
> for several reasons.
>
> - I have never thought of using type hints and default arguments this way
> until I found it by accident.
> - I have never seen someone else using it (I've just search installed PEAR
> packages, codebase of Symphony2, Zend2 and several others and found *one*
> function definition taking advantage of this*).
> - As far as i know other languages that support default argument values
> allow specifying default arguments only for rightmost function arguments.
> - As far as i know the only part of documentation that illustrates function
> declarations having default argument preceding non-default arguments is the
> one titled: "Incorrect usage of default function arguments" in
> http://www.php.net/manual/en/functions.arguments.php.
>
> I just wanted to be sure this is haw it is supposed to be used.
>
> * DibiColumnInfo::__construct(IDibiReflector $reflector = NULL, array $info)
> in
> https://github.com/dg/dibi/blob/master/dibi/libs/DibiDatabaseInfo.php#L458
>
> -- Oliver

Yes, we're talking about the same thing. I guess the reason that you
don't see arguments with default values before other arguments is
because they are only useful in combination with type hinting a class.
And, even when using it in this combination, most of us will probably
prefer the argument with the default value at the end, so we can omit
this parameter when calling the function. It seems to me you might be
thinking a little bit too much inside a Java box ;)

- Matijn

--- End Message ---
--- Begin Message ---
On May 31, 2012, at 7:45 PM, Ross McKay wrote:

> On Thu, 31 May 2012 13:21:07 -0400, Tedd Sperling wrote:
> 
>> [...]
>> I watched a interview today where an security expert claimed that 
>> the Flame Virus was written in a scripted language named lua 
>> (http://www.lua.org/).
> 
> That's surprising... I'm intrigued, can you supply a link?

No, there was no link. If I remember correctly, it was an interview done on Fox 
News.


>> He said that this was unusual because typically such viruses are
>> written in languages like Ruby-on-Rails and such.
> 
> Um, really? I very much doubt that. AFAIK, most true viruses are written
> in a compiled language, and many trojans as well. RoR websites would
> definitely be a vulnerability target though...

Yeah, that's what I thought, but this guy was held out to be one of the 
foremost experts on cyber-warfare. So, I listened and asked.

Cheers,

tedd

_____________________
tedd.sperl...@gmail.com
http://sperling.com



--- End Message ---
--- Begin Message ---
On Jun 3, 2012 12:05 PM, "Tedd Sperling" <t...@sperling.com> wrote:
>
> On May 31, 2012, at 7:45 PM, Ross McKay wrote:
>
> >> He said that this was unusual because typically such viruses are
> >> written in languages like Ruby-on-Rails and such.
> >
> > Um, really? I very much doubt that. AFAIK, most true viruses are written
> > in a compiled language, and many trojans as well. RoR websites would
> > definitely be a vulnerability target though...
>
> Yeah, that's what I thought, but this guy was held out to be one of the
foremost experts on cyber-warfare. So, I listened and asked.

    Actually, that's not true anymore. Flame was indeed written in Lua (and
you can find the source if you look), and while that choice of language is
a bit surprising, since it's a gaming language, the choice of distributing
a script-based virus/worm is not unique. Remember, WSH viruses and worms,
though not as prevalent today, were some of the most widespread and
destructive forms of malware in history --- a la
Loveletter/Lovebug/ILOVEYOU.

--- End Message ---
--- Begin Message ---
Disabled cookies use to be a problem years ago.  What's your experience these 
days.

I need it for my session ID. As I read the docs, the old method of appending it to the URL is a security issue.

I can obviously save the ID in a temp file which can be read by all the pages needing it.

Al....

--- End Message ---

Reply via email to