Skip to main content
16 events
when toggle format what by license comment
Apr 24, 2015 at 17:54 comment added user7043 Oh, nevermind about #1, I misread. And it's not about who gets to use = but that there are three options to begin with. Each and every language feature has to pull its weight, and two of these three do not IMHO.
Apr 24, 2015 at 17:15 comment added supercat @delnan: The existence of syntactic options for the first two would not imply that code that wanted #3 couldn't keep using the existing syntax. Given the dynamic nature of Python (not sure about Ruby) I'm not quite sure how #1 could consistently be detected prior to execution.
Apr 24, 2015 at 16:35 comment added user7043 @supercat Of course I would be opposed, first because of what I wrote in the question, second because two additional syntax constructs has all the downsides of one additional syntax constructs, only more so, and third because your case (1) strikes me as underachieving: If such a check is made, it can and should be made before execution.
Apr 24, 2015 at 16:14 comment added supercat ...even when reading code I would think it would be helpful to know which of the above was intended in case context doesn't make it clear.
Apr 24, 2015 at 16:13 comment added supercat Would you be opposed to the idea of being able to syntactically distinguish the three cases: (1) I don't expect any variable already exists with this name, and if one does the code is overwriting something it shouldn't so execution should trap; (2) I expect that I'm updating something that already exists with this name, and if it doesn't the code isn't updating what it's supposed to so execution should trap; (3) I want this to create or update the thing in question as appropriate. There are times when #3 really is most useful, but...
Aug 2, 2014 at 23:17 vote accept Aviv Cohn
Jul 24, 2014 at 10:40 comment added Alexander Gelbukh Completely agree: readability is extremely important. You agree that preventing bugs is important. You disagree with that declarations help preventing bugs. I disagree with that declarations hurt readability. Perhaps we can agree to disagree :-)
Jul 24, 2014 at 9:29 comment added user7043 How's that? I mean, I completely agree that it's better to not have bugs in the first place (I just don't see declarations helping with that to any significant degree). However, the need to read the code doesn't make debugging even less desirable: Reading is an integral part of debugging, it's already accounted for (consciously or not) in our feeling that it's hard work and takes a long time and is generally undesirable. If anything, this connection elevates the importance of readability since even debugging benefits from it.
Jul 24, 2014 at 9:22 comment added Alexander Gelbukh Which is one more argument for a language to prevent the need in debugging in the first place.
Jul 24, 2014 at 9:17 comment added user7043 @AlexanderGelbukh Note that the bug you describe is due to an interaction of several PHP features (chiefly references) and IIUC can't happen in that way in other languages lacking declarations. As for writing/debugging: Note that most debugging strategies (from low-tech "staring at it until it becomes clear" to fancy time-traveling debuggers) include a significant chunk of reading the code being debugged.
Jul 24, 2014 at 1:06 comment added Alexander Gelbukh Another argument against this answer: an indirect evidence of whether declarations are useful for humans in reading is that in most human languages it's obligatory to indicate with every use of a word (=variable) whether a it introduces a new object or refers to an existing one. In English we use articles a and the for this -- obligatorily with each use of each noun! In other languages there are other means, but the phenomenon seems to be universal. Humans should extremely need articles (=declarations) to avoid misunderstandings (=bugs).
Jul 24, 2014 at 0:58 comment added Alexander Gelbukh BTW, your main argument is: what matters in a program is how it reads (it's written once and read many), and for this no need to declare things. I disagree: I think what matters most is how it executes -- whether it produces correct results. I even suspect that in case of scripting languages the majority of programs (which are small programs) are written once, debugged many, and read never -- that is, the most part of the effort is in writing and debugging, not in reading. Reducing bugs is the main purpose of a language.
Jul 24, 2014 at 0:47 comment added Alexander Gelbukh Please see this my answer. As you see, it was unexpected for quite a number of people, me including, so that I had to experiment a lot. Now imagine how many incorrect programs there are out there due to such a bug.
Jul 23, 2014 at 17:32 comment added user7043 @AlexanderGelbukh I don't know PHP well enough to identify the cause, would you mind explaining?
Jul 23, 2014 at 13:21 comment added Alexander Gelbukh Here is an example of a bug in PHP caused by lacking declarations, from a practical case: $a = [1, 2, 3]; foreach ($a as $k => &$v) $v++; foreach ($a as $k => $v) echo "$k => $v\n";
Jul 19, 2014 at 23:38 history answered user7043 CC BY-SA 3.0