tag:blogger.com,1999:blog-18677687.post113617446517122804..comments2024-03-27T15:13:24.764-04:00Comments on Computer Science Teacher: Programming Languages Are HorribleAlfred Thompsonhttp://www.blogger.com/profile/05575057876858763822noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-18677687.post-41981674595517996162014-04-25T12:23:52.531-04:002014-04-25T12:23:52.531-04:00I think there is always a sort of trade off betwee...I think there is always a sort of trade off between what is easy to parse and what is natural for people. Terminators like curly braces and semicolons to make parsing easier. White space is more natural for humans but opens up ambiguity pretty easily and ambiguity is seldom a good thing in programming. Alfred C Thompson IIhttps://www.blogger.com/profile/06011086242006020298noreply@blogger.comtag:blogger.com,1999:blog-18677687.post-65872052419181047152014-04-23T15:29:27.216-04:002014-04-23T15:29:27.216-04:00"I would be interested in knowing why languag..."I would be interested in knowing why languages define code blocks using different approaches. Is there something better about the indent as opposed to EndIf as opposed to curly brackets?"<br /><br />Based on conversations I've had with Python advocates, they despise syntax. They feel that things like curly braces are annoyances that get in the way. They just don't like them. Perhaps there are other reasons, but I don't know why.<br /><br />As a curly-brace-advocate, though, I will say that this is grounded in compiler design theory and context-free grammars. One fundamental principle from that area is that white-space should never be significant. Parsing should be done based on an input stream of symbols with an unambiguous grammar. For instance, the infamous if structure can be defined as:<br /><br />IF : if EXPR BLOCK<br /><br />That is, an IF consists of the keyword "if" followed by an expression EXPR and a block BLOCK. These definitions could be expanded (note that | is for listing multiple options):<br /><br />EXPR : EXPR == EXPR<br /> | IDENT = EXPR<br /> | ( EXPR )<br /> | ...<br /><br />BLOCK : IDENT = EXPR;<br /> | STATEMENT<br /> | { BLOCK }<br /> | ...<br /><br />From a parse-tree structure, this ends up being easy to automate. However...it makes it hard to program. In general, programming language designers have focused on how to make it easy to build a compiler while ignoring the cognitive difficulties of how to write code. Whether or not that is the right choice is a matter of debate.Michael S. Kirkpatricknoreply@blogger.comtag:blogger.com,1999:blog-18677687.post-79538302014534349232014-04-21T10:36:20.802-04:002014-04-21T10:36:20.802-04:00I like EndIf. It is just so simple. I really do ...I like EndIf. It is just so simple. I really do not like the indent method of Python. The end of a block simply does not jump out at you like the good ol' EndIf. I would be interested in knowing why languages define code blocks using different approaches. Is there something better about the indent as opposed to EndIf as opposed to curly brackets?Garthnoreply@blogger.comtag:blogger.com,1999:blog-18677687.post-89379339249637125472014-04-16T16:36:07.235-04:002014-04-16T16:36:07.235-04:00I wish I had a reference to point to (can't re...I wish I had a reference to point to (can't remember where I saw it and don't feel like looking it up), but this problem also plagues indentation-based languages like Python, except in reverse. Specifically, if you do something like:<br /><br />if False:<br><br /> DoSomething<br><br /><br><br /> DoSomethingElse<br><br /><br />In the study I am thinking of, a very large number (something like 65%) of Python programmers said that DoSomethingElse would be executed. Even for the most experienced demographic, a majority still got it wrong.<br /><br />I think the important takeaway is that there is no perfect language. You should use the language that is most appropriate for the concepts you want to cover. For me (I teach systems courses such as OS), that language is C and only C. It's not that I perceive other languages as crutches. It's that other languages get in the way. If I'm trying to talk about page tables or scheduling queue implementations, higher level languages block me from having direct access to the machine-level features that I need.<br /><br />For high school and CS1, I think languages like Python, Ruby, etc., are better, because they allow you to talk about computational thinking concepts instead of dwelling on syntax.Michael S. Kirkpatricknoreply@blogger.comtag:blogger.com,1999:blog-18677687.post-72314666155090692982014-04-16T10:35:50.663-04:002014-04-16T10:35:50.663-04:00The Go programming language with its strict and un...The Go programming language with its strict and uniform syntax prohibits such errors. There is no if without curly braces.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-18677687.post-62557375276251374842014-04-16T07:25:58.908-04:002014-04-16T07:25:58.908-04:00This is a valid concern, but you are looking at th...This is a valid concern, but you are looking at the problem in isolation. You must know what I'm going to point out, but for posterity:<br /><br />There are good reasons for C's lax syntax. It needs to be easy to generate by other programs, and it tries to be concise (to the point of obfuscation). The solutions are obvious: using the appropriate tools. Even the most basic static code analysis tool would catch a mistake like this.<br /><br />As an educator, why not give your students an exercise: writing a static code analysis tool that detects possible errors?Borishttps://www.blogger.com/profile/09839114065575502649noreply@blogger.comtag:blogger.com,1999:blog-18677687.post-63255395969208367722014-04-15T10:51:38.763-04:002014-04-15T10:51:38.763-04:00Languages like Python use indentation for blocks i...Languages like Python use indentation for blocks instead of brackets or "end if", so that's an example of a language that follows "do what I mean" when writing indented code. <br /><br />Some editors like Visual Studio have "format my code" features that will indent everything properly so it's easier to catch things like your first example. In that case, Visual Studio would remove the indent from the second line, and it would be (maybe) apparent to the programmer that the result won't be what they might have thought. It may even do that formatting and auto-indenting as you type. <br /><br />You're right, this is a crummy thing to have to learn, and we often learn it the hard way. In this case, maybe a different set of tools will help? <br /><br />Don Brueyhttps://www.blogger.com/profile/00786239905109401570noreply@blogger.com