4 ms·
I know we're in brainstorming mode, so please don't interpret this as criticism of your suggestion. Don't named variables serve the same purpose as pronouns? W
by sowbug 9y ago
I know we're in brainstorming mode, so please don't interpret this as criticism of your suggestion.
Don't named variables serve the same purpose as pronouns? What's an example of a pronoun-like usage in a hypothetical programming language?
- kd5bjo 9y ago_ in the Python interactive shell seems like a good example, it is always the result of the previous statement. It'd also be nice to have some sort of statement-scoped variable to help reduce error-prone repetition without polluting the block namespace, as functions often take multiple arguments that are derived from the same intermediate value.
- earenndil 9y agoI imagine the parent meant something like this: if (x > maximum) { it = maximum; // 'it' refers to x } As for a hypothetical useage, I imagine it would make refactoring easier in some places, but could also open code up to potential errors (accidentally referenced another variable? 'it' suddenly changes and you didn't notice!)
- fragmede 9y agoNamed variables require the creation of, well, names. Naming things is one of the few hard problems in computer science, and at the extreme ends is single-letter variable names, or variables_that_are_short_phrases, which are annoying to use. Several languages have usage I'd consider "pronoun-like". Perl has $_ and Bash has $?. Unfortunately, "$?" doesn't exactly roll off the tongue, and there's some truth to criticisms of Perl readability. That may be related to the the quantity of the that it supports though. self in various languages supporting OO is a fairly common example of what I'd consider good pronoun-like usage - if I'm inside a method that belongs to a class, what self refers to is accessible and largely unambiguous.
- OtterCoder 9y agoSee, I hate the use of self, or this in code. We want to specify things exactly in code, and deliberately adding that sort of indirection seems halfway mad. If forced to write classes, I would much rather refer to the class name from within methods, or something similar.
- imauld 9y agoThis is valid Python: >>> class Foo: ... def __init__(Foo, x): ... Foo.x = x ... >>> foo = Foo(5) >>> foo.x 5 The variable name `self` is a convention as is `cls`. You can name the first argument to a method whatever you please. The same is true for method receivers in Go: type Foo struct { X int } func (Foo Foo) Bar() int { return Foo.X * 2 } That will compile and perform as expected. Not sure about Java/C# but in Javascript you can bind `this` to another variable if you'd like: var Foo = { x: 5, foo: function() { Foo = this return Foo.x * 2; } }
- mcphage 9y ago> Don't named variables serve the same purpose as pronouns? Variable names are closer to real names, than pronouns. Try taking any piece of narration and remove the pronouns; it'll read something like: Mark woke up in the morning when Mark's alarm went off. Mark dangled Mark's feet over the side of Mark's bed, and slipped Mark's feet into Mark's slippers. A lot of code reads like that, too.