Forum: Ruby-core [ruby-trunk - Feature #7432][Open] Explicit way to define local variable in scope

Posted by prijutme4ty (Ilya Vorontsov) (Guest)
on 2012-11-25 08:32
(Received via mailing list)
Issue #7432 has been reported by prijutme4ty (Ilya Vorontsov).

----------------------------------------
Feature #7432: Explicit way to define local variable in scope
https://bugs.ruby-lang.org/issues/7432

Author: prijutme4ty (Ilya Vorontsov)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


Imagine code such as this
  def test_smth
    result = nil
    assert_nothing_raised { result = some_slow_calculation }
    assert_equal expected_answer, result
  end
Line `result = nil` means nothing more than our intention to simply bind 
variable `result` in scope of assertion block with outer local variable. 
In large methods it can be much heavier to find out this obscured 
intention.
It may be better to introduce a method (if it can be implemented) or a 
keyword which simply creates a local variable (probably with nil value 
just to mark its existence)

define_variable 'x' or (define_variable x if it's a keyword)
Posted by charliesome (Charlie Somerville) (Guest)
on 2012-11-25 09:18
(Received via mailing list)
Issue #7432 has been updated by charliesome (Charlie Somerville).


This should definitely not be a method, however I would welcome a 
'local' keyword for this purpose.
----------------------------------------
Feature #7432: Explicit way to define local variable in scope
https://bugs.ruby-lang.org/issues/7432#change-33850

Author: prijutme4ty (Ilya Vorontsov)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


Imagine code such as this
  def test_smth
    result = nil
    assert_nothing_raised { result = some_slow_calculation }
    assert_equal expected_answer, result
  end
Line `result = nil` means nothing more than our intention to simply bind 
variable `result` in scope of assertion block with outer local variable. 
In large methods it can be much heavier to find out this obscured 
intention.
It may be better to introduce a method (if it can be implemented) or a 
keyword which simply creates a local variable (probably with nil value 
just to mark its existence)

define_variable 'x' or (define_variable x if it's a keyword)
Posted by mame (Yusuke Endoh) (Guest)
on 2012-11-25 10:17
(Received via mailing list)
Issue #7432 has been updated by mame (Yusuke Endoh).

Status changed from Open to Assigned
Assignee set to matz (Yukihiro Matsumoto)
Priority changed from Normal to Low
Target version set to Next Major

Assigning to matz, but don't hold your breath; matz has rejected such a 
explicit variable declaration syntax many times.

--
Yusuke Endoh <mame@tsg.ne.jp>
----------------------------------------
Feature #7432: Explicit way to define local variable in scope
https://bugs.ruby-lang.org/issues/7432#change-33851

Author: prijutme4ty (Ilya Vorontsov)
Status: Assigned
Priority: Low
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: Next Major


Imagine code such as this
  def test_smth
    result = nil
    assert_nothing_raised { result = some_slow_calculation }
    assert_equal expected_answer, result
  end
Line `result = nil` means nothing more than our intention to simply bind 
variable `result` in scope of assertion block with outer local variable. 
In large methods it can be much heavier to find out this obscured 
intention.
It may be better to introduce a method (if it can be implemented) or a 
keyword which simply creates a local variable (probably with nil value 
just to mark its existence)

define_variable 'x' or (define_variable x if it's a keyword)
Posted by Thomas Sawyer (7rans)
on 2012-11-25 12:03
(Received via mailing list)
Issue #7432 has been updated by trans (Thomas Sawyer).


I have always been curious why there is no dynamic way to create local 
variables (other then eval).

Eg. x = 10 might be dynamically written:

  local :x, 10

Since we can create just about anything else dynamically, it seems like 
stark omission.

----------------------------------------
Feature #7432: Explicit way to define local variable in scope
https://bugs.ruby-lang.org/issues/7432#change-33852

Author: prijutme4ty (Ilya Vorontsov)
Status: Assigned
Priority: Low
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: Next Major


Imagine code such as this
  def test_smth
    result = nil
    assert_nothing_raised { result = some_slow_calculation }
    assert_equal expected_answer, result
  end
Line `result = nil` means nothing more than our intention to simply bind 
variable `result` in scope of assertion block with outer local variable. 
In large methods it can be much heavier to find out this obscured 
intention.
It may be better to introduce a method (if it can be implemented) or a 
keyword which simply creates a local variable (probably with nil value 
just to mark its existence)

define_variable 'x' or (define_variable x if it's a keyword)
Posted by matz (Yukihiro Matsumoto) (Guest)
on 2012-11-25 13:49
(Received via mailing list)
Issue #7432 has been updated by matz (Yukihiro Matsumoto).

Status changed from Assigned to Rejected

Since I am sick of 'var' and 'local' in other languages, I don't want to 
add explicit local variable declaration, that requires a new keyword. 
Introducing a new keyword may break existing programs.

@trans Your idea would eliminate many chances to optimize.

Matz.


----------------------------------------
Feature #7432: Explicit way to define local variable in scope
https://bugs.ruby-lang.org/issues/7432#change-33856

Author: prijutme4ty (Ilya Vorontsov)
Status: Rejected
Priority: Low
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: Next Major


Imagine code such as this
  def test_smth
    result = nil
    assert_nothing_raised { result = some_slow_calculation }
    assert_equal expected_answer, result
  end
Line `result = nil` means nothing more than our intention to simply bind 
variable `result` in scope of assertion block with outer local variable. 
In large methods it can be much heavier to find out this obscured 
intention.
It may be better to introduce a method (if it can be implemented) or a 
keyword which simply creates a local variable (probably with nil value 
just to mark its existence)

define_variable 'x' or (define_variable x if it's a keyword)
Posted by Thomas Sawyer (7rans)
on 2012-11-25 15:12
(Received via mailing list)
Issue #7432 has been updated by trans (Thomas Sawyer).


I see why then. Thanks.
----------------------------------------
Feature #7432: Explicit way to define local variable in scope
https://bugs.ruby-lang.org/issues/7432#change-33859

Author: prijutme4ty (Ilya Vorontsov)
Status: Rejected
Priority: Low
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: Next Major


Imagine code such as this
  def test_smth
    result = nil
    assert_nothing_raised { result = some_slow_calculation }
    assert_equal expected_answer, result
  end
Line `result = nil` means nothing more than our intention to simply bind 
variable `result` in scope of assertion block with outer local variable. 
In large methods it can be much heavier to find out this obscured 
intention.
It may be better to introduce a method (if it can be implemented) or a 
keyword which simply creates a local variable (probably with nil value 
just to mark its existence)

define_variable 'x' or (define_variable x if it's a keyword)
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.