News for hackers. Stuff that matters.
Re:PHP 7 deployment at Dailymotion by cjhanks on Thursday October 13, 2016 @11:43PM (#12705999)
That scope logic is normal in many interpreted languages. I love it in Python.
Re:PHP 7 deployment at Dailymotion by haimez on Thursday October 13, 2016 @11:51PM (#12706026)
Python does support block scoping- so no- it doesn't work there. Also, if you need to use variables in outer scopes, it's ok to declare them there. There is literally, and I mean this, literally- no possible justification for using inner-scoped variables in an outer scope that they weren't declared in.
Re:PHP 7 deployment at Dailymotion by cjhanks on Friday October 14, 2016 @12:18AM (#12706114)
if predicate: A = 3 else: A = 5

B = A / 2

...

Why forward declare A = None?

Re:PHP 7 deployment at Dailymotion by haimez on Friday October 14, 2016 @12:25AM (#12706134)
Because it announces that you intend to use the name 'A' in the current scope after some assignment happens in a nested one. It's intentional.

It /can/ be useful, but it should be opt-in. JavaScript had to figure this out with their 'var' declaration scoping too.

Also, try:

A = (predicate) ? 3 : 5

Or, in a language that embraces expressions instead of statements:

val A = if (predicate) { 3 } else { 5 }

These are all more intentional, concise, and readable than allowing variables to outlive their scope by default.

Re:PHP 7 deployment at Dailymotion by ucho on Friday October 14, 2016 @04:46AM (#12706834)
Java has also alternative approach:

    final a;
    if (predicate) {
     a = 3;
    } else {
     a = 5;
    }
`final` makes it possible for variable to be assigned exactly once. Verbose but useful when "?:" is not a good fit.