tag:blogger.com,1999:blog-2564777502681463717.post1477867183672088909..comments2023-12-31T10:17:57.560-05:00Comments on Teaching, Playing, and Programming: In praise of mandatory indentation for novice programmersChris Okasakihttp://www.blogger.com/profile/18247315355264748920noreply@blogger.comBlogger39125tag:blogger.com,1999:blog-2564777502681463717.post-58986432199533862062009-10-15T08:29:01.951-04:002009-10-15T08:29:01.951-04:00Stumbling upon this thread about the EastWest prog...Stumbling upon <a href="http://lambda-the-ultimate.org/node/3567" rel="nofollow">this thread</a> about the EastWest programming environment (with a structure editor), I saw <a href="http://www.cs.cmu.edu/~ajko/papers/Ko2005TextEditing.pdf" rel="nofollow">this study</a> about editing that may help building worthwhile structure editors.<br /><br />The results are very interesting. Basically, the programmers follow a limited set of pattern when editing code. For instance, they tend to know what kind of loop they need beforehand. That suggest structure editors could be made even more usable than free-form text editing. They would have to follow slightly different rules than the current ones do, however (for instance in the case of infix expressions).<br /><br />Unfortunately, the study is limited to Java by experienced programmers. Your case is almost the exact contrary. If you care about implementing some sort of key-logger to your student's programming environment, maybe you could collect more data to see if this study could be generalized or not. (Who knows, this could even be worth a paper :-)Loup Vaillanthttps://www.blogger.com/profile/04423202814830526483noreply@blogger.comtag:blogger.com,1999:blog-2564777502681463717.post-49056518355255407722009-10-13T12:14:18.082-04:002009-10-13T12:14:18.082-04:00No, I never gave any thought to a structure editor...No, I never gave any thought to a structure editor. I had some experience with a structure editor many, many years ago, and it was awful. The problem was that you had to make your decisions in a particular order. For example, you couldn't say, "I know I want a loop here, but I don't know what kind of loop yet. I do know what the body should look like, so I'll fill that in first, and then come back and decide what kind of loop."<br /><br />Of course, that was a long time ago, and structure editors may have improved since then.Chris Okasakihttps://www.blogger.com/profile/18247315355264748920noreply@blogger.comtag:blogger.com,1999:blog-2564777502681463717.post-47411218850968253312009-10-13T11:54:50.372-04:002009-10-13T11:54:50.372-04:00Did you think about going even further than mandat...Did you think about going even further than mandatory indentation? I think about structured editors. With them, syntax errors are just impossible, making the whole thing even easier (hopefully).Loup Vaillanthttps://www.blogger.com/profile/04423202814830526483noreply@blogger.comtag:blogger.com,1999:blog-2564777502681463717.post-16162041890815848262009-02-28T23:55:00.000-05:002009-02-28T23:55:00.000-05:00Dmethodair, I'm glad to hear you're doing well. T...Dmethodair, I'm glad to hear you're doing well. Thanks for the kind words!Chris Okasakihttps://www.blogger.com/profile/18247315355264748920noreply@blogger.comtag:blogger.com,1999:blog-2564777502681463717.post-1440794464221853102009-02-28T23:40:00.000-05:002009-02-28T23:40:00.000-05:00The language mentioned (I believe) is called Hudso...The language mentioned (I believe) is called Hudson and I might have been one of the recipients of it in 2003. I am currently working on my masters degree at UC San Diego and I still remember that class to this day for several reasons, although I do not have experience in large scale projects at a commercial level. First, I am incredibly particular about indentation now to the point that if it becomes too unwieldy, I find another way to do it. Therefore, my code is much easier to read and debug. Also, despite being behind in several areas compared to my colleages, that language helped me to understand programming languages in a way that almost none of the other masters students understand. My other friends getting CS degrees could (at the time) completely outdo me with C but I knew what was going on better than any of them and that still holds true for the most part. I really do think that forcing indentation as part of good coding practice really helped to focus on WHAT the language was teaching us and not HOW to do it. I fought with syntax very little in that class and it helped a great deal. Side not: Chris, thanks for a great class that outdid everyone I know at the undergrad level. I can't believe that I stumbled onto this but.Unknownhttps://www.blogger.com/profile/14883154752448854856noreply@blogger.comtag:blogger.com,1999:blog-2564777502681463717.post-15214076598376263242008-05-05T13:00:00.000-04:002008-05-05T13:00:00.000-04:00Some people think of the eye as simply an input de...Some people think of the eye as simply an input device. But the eye along with early visual processing is something of a computer or a pre-processor that massages visual input.<BR/><BR/>It is very good at doing certain things like grouping sub-elements into larger elements. You can get a sense of what is happening by looking at some of the <A HREF="http://en.wikipedia.org/wiki/Gestalt_psychology#Pr.C3.A4gnanz" REL="nofollow">perceptual "laws" in Gestalt psychology</A>.<BR/><BR/>Indentation and appropriate use of white space are very effective at allowing you to easily group elements with less conscious processing.<BR/><BR/>When teaching people how to program, you have to be concerned with human limitations. You can't dump too much on the learners at once. You have to find a route through the material where you can add sufficiently digestible chunks.<BR/><BR/>I suspect that by using indentation rather than tokens to denote blocks of code can be very helpful in this. The eye will pick it up allowing the student to focus on the "real" (semantic) problem at hand. <BR/><BR/>And once block structures such as conditionals, loops, methods, etc. are well understood, picking up token-based block delimiters is much easier. No one is saying that students shouldn't learn that, but we're trying not to throw too much at the students too quickly.<BR/><BR/>And that's why I disagree with dan's disagreement.Eric I.https://www.blogger.com/profile/10919653944810042664noreply@blogger.comtag:blogger.com,1999:blog-2564777502681463717.post-57398506560881114722008-05-02T19:29:00.000-04:002008-05-02T19:29:00.000-04:00For some courses, I would be happy to use Python. ...For some courses, I would be happy to use Python. For that particular course, however, Python would not have worked (for reasons having nothing to do with indentation).Chris Okasakihttps://www.blogger.com/profile/18247315355264748920noreply@blogger.comtag:blogger.com,1999:blog-2564777502681463717.post-58251087515553066452008-05-02T18:21:00.000-04:002008-05-02T18:21:00.000-04:00Wouldn't it be more inspiring for your students if...Wouldn't it be more inspiring for your students if they used Python instead of your language? The more advanced students could use their skills and create web pages with Django or using one of the (many) libraries that are out there.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2564777502681463717.post-51479920348072785832008-03-15T12:10:00.000-04:002008-03-15T12:10:00.000-04:00rgrig,I agree with you in principle. I don't want...rgrig,<BR/><BR/>I agree with you in principle. I don't <I>want</I> something as simple as indentation to matter more than than a host of other properties that seem more important to me. <BR/><BR/>The catch is that I have four years of data that I can't explain any other way. It's certainly possible that I'm misinterpreting or misattributing my data, but I don't think I am. When my philosophy contradicts years of data, I have to accept, however reluctantly, that one or the other is probably wrong.Chris Okasakihttps://www.blogger.com/profile/18247315355264748920noreply@blogger.comtag:blogger.com,1999:blog-2564777502681463717.post-67342265732766996212008-03-15T07:43:00.000-04:002008-03-15T07:43:00.000-04:00I realized that although I'm a bit against forcing...I realized that although I'm a bit against forcing indentation (my opinion being better summarized in the previous comment) I do it when teaching my wife how to program: She writes some code, gets stuck, asks me for help, and I tell her that I can't read code written like that, so I'll help her after she fixes the spacing. (And yes, I do think this is better than forcing her in the first place to indent code. Now she *experienced* one reason indentation is good: Because otherwise she won't get help from me and perhaps not even other people.)rgrighttps://www.blogger.com/profile/02991214367108471744noreply@blogger.comtag:blogger.com,1999:blog-2564777502681463717.post-64655523814242235362008-03-04T07:35:00.000-05:002008-03-04T07:35:00.000-05:00Thanks for a very interesting post! It certainly c...Thanks for a very interesting post! It certainly comes as a surprise to me that your students seem to pick up indenting quickly. That made me wonder: What does the error messages look like when the students fail to indent properly? And I also wonder whether you think the quality of those error messages have anything to do with the pace the students pick proper indenting.<BR/><BR/>One of the reasons I ask is because of my experience with Haskell. Sometimes the error messages can be quite confusing of one mis-indents, even for a senior Haskell programmer.Josefhttps://www.blogger.com/profile/13272830598221833253noreply@blogger.comtag:blogger.com,1999:blog-2564777502681463717.post-654698340508786862008-02-27T09:55:00.000-05:002008-02-27T09:55:00.000-05:00I think that indentation is very easy to do for ed...I think that indentation is very easy to do for editors, it shouldn't be a "feature" of the language.<BR/><BR/>Novices shoud be right at home with an auto indenting editor, even in environments like scheme where highly nested syntax may be difficult to grok, environments like DrScheme help a lot to novices without limiting the experts.<BR/><BR/>There is another point in adding syntax to mark blocks: tools, you may take whatever source and reindent it to your taste with the propper tool, for example I program according to the syntax rules of my own editors (vim/emacs), I can take any code in the wild and reformat it in a matter of seconds with tools like indent(1) or perltidy.<BR/><BR/>Forcing syntax just gain a little bit of compactness, but takes a lot of flexibility, you mention something about adding debug statements, well I spend an awfull lot of time debugging and refactorizing code, things that are much easier to do without indentation restrictions, when everything is in place, you may allways reformat your code layout automatically.Jose Reyhttps://www.blogger.com/profile/15071755167581242815noreply@blogger.comtag:blogger.com,1999:blog-2564777502681463717.post-18351677596771872692008-02-26T15:20:00.000-05:002008-02-26T15:20:00.000-05:00Grant, I wish I knew. I certainly haven't done an...Grant, I wish I knew. I certainly haven't done any formal experiment to try to distinguish between causation and correlation. Having said that, I do believe there's at least a little causation here.<BR/><BR/>As for students vs professionals, I've only been working with students. My experience is that they benefit a lot. My guess is that professionals would benefit also, but to a much smaller degree.Chris Okasakihttps://www.blogger.com/profile/18247315355264748920noreply@blogger.comtag:blogger.com,1999:blog-2564777502681463717.post-64973837952501493102008-02-26T14:56:00.000-05:002008-02-26T14:56:00.000-05:00Chris great article.Is it causation or correlation...Chris great article.<BR/>Is it causation or correlation?<BR/>Does it apply only to students or professionals?grant rettkehttps://www.blogger.com/profile/09439997834215273665noreply@blogger.comtag:blogger.com,1999:blog-2564777502681463717.post-5041516966089900422008-02-26T14:02:00.000-05:002008-02-26T14:02:00.000-05:00I have read a lot of existing code while working a...I have read a lot of existing code while working at major software developers (Microsoft, Google, etc.) and when I see procedures with indenting 5 or 6 or more levels deep, I cringe. I have an especially vivid memory of debugging into a procedure in a shipping product where I was stepping through statements with over 80 spaces of indent in front of them - the procedure itself was 2200 lines long!<BR/><BR/>My point is: If you need such high levels of indenting you're already doing something wrong. You no longer have single-purpose functions, you no longer have code that is understandable, you certainly no longer have code you can test or get coverage on.<BR/><BR/>So I'm not really impressed by complaints that when copying code blocks from point A to point B you might have to adjust your indentation from 5 levels to 3 levels. What you really <I>should</I> be doing is creating smaller single-purpose functions that can be understood and tested, and then building on them.<BR/><BR/>(Plus, why isn't your text editor letting you indent/outdent code blocks as a chunk? Use better tools!)<BR/><BR/>As you mention: less is more. Languages with lighter syntax (e.g., Haskell, Python) are easier to code <I>properly</I> - and it is especially important that the syntax for code abstraction - that is, function definition - is light. And - that there is a light anonymous function syntax too - because coming up with a useful name for a function is frequently an additional cognitive load, contributing to the programmer's failure to break code into smaller chunks.Davidhttps://www.blogger.com/profile/09358968282816697343noreply@blogger.comtag:blogger.com,1999:blog-2564777502681463717.post-48330933277306780432008-02-26T11:38:00.000-05:002008-02-26T11:38:00.000-05:00rgrig, thanks for your thoughtful response. You a...rgrig, thanks for your thoughtful response. You asked "<I>Second, your statement just doesn't fly with me. You mean that they are less used to parentheses from math?</I>"<BR/><BR/>Yes, that's exactly what I mean. They know at some intellectual level how parentheses work, but many of them haven't really internalized them, especially nested parentheses. (Don't get me started on the state of mathematics education in the US!)<BR/><BR/>Here's an example from a Discrete Math course I taught a few years ago. The students were working on a proof about factorials on the boards around the room. A subterm in the statement to be proved was "n-(k+1)". In their very first step, all but one or two of the students dropped the parentheses to get "n-k+1". As I went around the rooming, telling them that the two weren't the same, most of them didn't believe me until I forced them to plug actual numbers in.Chris Okasakihttps://www.blogger.com/profile/18247315355264748920noreply@blogger.comtag:blogger.com,1999:blog-2564777502681463717.post-30579361681565046682008-02-26T11:23:00.000-05:002008-02-26T11:23:00.000-05:00As many people have noted, tabs can be a problem w...As many people have noted, tabs can be a problem when using mandatory indentation. Of course, they're also a problem in languages that don't require indentation, but admittedly not as severe.<BR/><BR/>In my case, the language forbids tabs, and I provide modest editor support to make using spaces only easier.Chris Okasakihttps://www.blogger.com/profile/18247315355264748920noreply@blogger.comtag:blogger.com,1999:blog-2564777502681463717.post-48533713847244980902008-02-26T11:11:00.000-05:002008-02-26T11:11:00.000-05:00You forgot one source of trouble for meaningful in...You forgot one source of trouble for meaningful indentation: the issues triggered by space and tab.<BR/><BR/>Have you tried to allow only one of those to see if it had an impact on the student learning abilities?renoXhttps://www.blogger.com/profile/03221431358667243128noreply@blogger.comtag:blogger.com,1999:blog-2564777502681463717.post-21309848616718139622008-02-26T08:31:00.000-05:002008-02-26T08:31:00.000-05:00Why I don't like mandatory indenting (as a profess...Why I don't like mandatory indenting (as a professional programmer) is the problem of what the definition of a tab is. This is especially a problem when you have a space-tab sequence. Unix programs (generally) interpret a tab as "move to the next column which is a multiple of the tab-stop", while Windows programs (generally) interpret a tab as "move right the tab-stop number of columns. This is the same if you start in a tab-stop aligned column, but it's different if you're not. And this is not even dealing with changing the tab-stop.<BR/><BR/>Worse yet, this is an "invisible" error. You can't easily see that a space has snuck in somewhere, or that a tab has gotten replaced by spaces (or vice versa).<BR/><BR/>The only way I'd do this in production is by either outlawing tabs, or outlawing tabs anywhere except the beginning of the line (i.e. no non-tab character can come before a tab character), or some similar rule.Unknownhttps://www.blogger.com/profile/16634521018295906373noreply@blogger.comtag:blogger.com,1999:blog-2564777502681463717.post-3576800476710545062008-02-26T00:07:00.000-05:002008-02-26T00:07:00.000-05:00Michael, Tac-Tics,I agree that novices should know...Michael, Tac-Tics,<BR/><BR/>I agree that novices should know how to write readable good-formated code, but also they should to know to *why*.<BR/><BR/>You know, code formatting is very important aspect when you're working in team or when you're reading somebody's code(yeah, and thinking: "show me this idiot who wrote this unreadable garbage, I want to see his eyes"), but if an abstract newbie wants to work in team and understand another's code, [s]he *must* to know fundamental paradigms and algorithms. And it's more significant.<BR/><BR/>Have you ever thought about why SICP course is still used in MIT(yep, "unreadable" scheme + fundamentalism + math + paradigms + other "ugly stuff") or about why Don Knuth used abstract MIX language("unreadable" funny "assembler") in his cool books? <BR/><BR/>Imho, novice should, first of all, understand what is scopes, blocks, how interpreter/compiler works and only then(after [s]he knows what is AST, preprocessor, etc) eat all tasty sugar. In this case [s]he'll really know what the hell [s]he is doing and will know that indentation, parentheses, begin/end, etc just determine blocks. This is the key.<BR/><BR/>Good formated code is not a thing which should be learned in the university or enforced by some language, rather it's a thing that will be either automatically learned or after spending 10-60 minutes on reading few topics from any book about good-programming-style.Unknownhttps://www.blogger.com/profile/02722911073088851986noreply@blogger.comtag:blogger.com,1999:blog-2564777502681463717.post-4342547511143423832008-02-25T23:33:00.000-05:002008-02-25T23:33:00.000-05:00So, Chris, what is your teaching language like? Wh...So, Chris, what is your teaching language like? What concepts are you trying to teach with it? Any other interesting features?Arcane Sentimenthttps://www.blogger.com/profile/04144052171693893368noreply@blogger.comtag:blogger.com,1999:blog-2564777502681463717.post-76873653245786131132008-02-25T22:02:00.000-05:002008-02-25T22:02:00.000-05:00Dan, syntax does matter. It matters a lot. If it d...Dan, syntax does matter. It matters a lot. If it didn't, all code would be written with S-expressions.<BR/><BR/>The underlying concepts of CS are very important, and deciding between a bubblesort from a mergesort is indeed more important than deciding between tabs or spaces. But for first-year students, stick with what matters. Clean coding style is just as important as anything else. <BR/><BR/>If you write working, but unreadable code (and many students do exactly that), it makes your teacher's life miserable and it will make your coworkers miserable when they have to fix a bug in your code.Tac-Ticshttps://www.blogger.com/profile/14070765709653635739noreply@blogger.comtag:blogger.com,1999:blog-2564777502681463717.post-91394739360293575042008-02-25T20:33:00.000-05:002008-02-25T20:33:00.000-05:00DanFor an _intro_ course, you want to teach good _...Dan<BR/><BR/>For an _intro_ course, you want to teach good _habits_.<BR/><BR/>Once a person is familiar with the "rules", then they can start exploring when they do not apply in certain situations.Michaelangel007https://www.blogger.com/profile/16918754955275589020noreply@blogger.comtag:blogger.com,1999:blog-2564777502681463717.post-28066997790689323582008-02-25T20:15:00.000-05:002008-02-25T20:15:00.000-05:00I admit, I prefer explicit delimiters. (But then...I admit, I prefer explicit delimiters. (But then, I also prefer Tcl/Tk, which makes me nuts by most folks' standard anyway.)<BR/><BR/>But I remember many, many years ago, when I became a C programmer after having been mostly a Pascal programmer. Pascal was case-insensitive, and no matter how much I wanted to be consistent with the casing on my variable names, I never was. In C, of course, it simply wasn't an issue: if I didn't spell the name right, the code didn't compile. I much prefer the latter.Will Duquettehttps://www.blogger.com/profile/07842496412575851453noreply@blogger.comtag:blogger.com,1999:blog-2564777502681463717.post-49198370321531791592008-02-25T20:12:00.000-05:002008-02-25T20:12:00.000-05:00Indentation is good. Good programmers ask compiler...Indentation is good. Good programmers ask compilers to report all<BR/>warnings from the beginning of a project. When you have to manage<BR/>hundreds of lines of code, and even more, it is foolish not to<BR/>use the help of a tool that is much better than you at nitty-gritty<BR/>details. Warnings are not errors, and you can hide them. Doing<BR/>so means that you'll never be able to avail of the compiler as<BR/>a detective: If you turn on warnings in the middle of the project<BR/>you are swamped with useless messages and that's just more hay on<BR/>top of your needle. So, let the compiler help you with warnings.<BR/>(Static checkers like Spec# can be seen as pushing further this<BR/>philosophy.) I do not like, however, to be forced! Simply put,<BR/>forcing people to do something is bound to be far less effective<BR/>than convincing them. (That's one of the important reasons why<BR/>democracy works better than dictatorship. Note that I don't claim<BR/>there is any link between politics and indentation---just an<BR/>overstretched analogy.)<BR/><BR/>Progress seems to be about leaving out one percent. Java is a<BR/>dumbed down version of C++.<BR/>Haskell is an even more dumbed down version of... something.<BR/>(Come on, no assignment? That must give me the right to say<BR/>"dumbed down".) Yet, the dumbed down versions seem to work<BR/>better, probably because the volume of our brains is limited.<BR/>(At least according to Dijkstra.) The best programmers in my<BR/>experience are those able to cover the last few one percents<BR/>that history left out, should the need arise. You mock assembly<BR/>programmers? Well, all good programmers I know are at least able<BR/>to read assembly. (For example, Michal Moskal, one of the guys<BR/>behind the functional language Nemerle, is quite eager to dive<BR/>in and look at MSIL. He is also very good at writing insanely<BR/>optimized C code.)<BR/><BR/>So, yes, indentation is good and explicit markers are one of those<BR/>features we'll drop. Personally, I'd prefer editors that show<BR/>the code in whatever way you prefer and version control systems<BR/>that understand code (not only text). In such a world a group<BR/>of statements would be a group of statements, not a group of characters<BR/>in-between some delimiters or with a certain indentation.<BR/><BR/>Now let me attend to some of your statements and a comment.<BR/><BR/>1. You claim that students are used to indentation from PowerPoint<BR/>but not to curly brackets. First, I must admit that I never before<BR/>thought of PowerPoint as a vehicle for teaching programming.<BR/>This looks like a horror movie poster in my mind. But let me get<BR/>over personal taste. Second, your statement just doesn't fly with<BR/>me. You mean that they are less used to parentheses from math?<BR/>Even so, don't they need to understand parentheses anyway as a<BR/>way of grouping other stuff in their program?<BR/><BR/>2. You say that students don't indent programs in Notepad. Well, me<BR/>neither. I also don't write anything longer than 10 lines in Notepad.<BR/>I've learned the hard way, by writing programs that I was unable<BR/>to read later. Somehow the lesson stuck. Whenever someone tells me<BR/>that I must do something because the alternative is worse, the<BR/>message goes thru me.<BR/><BR/>3. You say that relying on indenting makes scanning and parsing harder.<BR/>Tools are made to make our lives easier, not the other way around.<BR/>(In other words, I agree.)<BR/><BR/>4. You say that John Dethridge was obfuscating his code. Are you sure?<BR/>For example, tomek repeatedly said that writing ugly code makes<BR/>it very hard to debug under the tight time constraints and that<BR/>outweighs the benefits you'd have from obfuscating the code. Also,<BR/>I've seen John Dethridge asking Egor "What's with all those spaces?<BR/>It looks awful!" Are you sure it's not just that you can't imagine<BR/>someone finding such compact (and unindented) code readable?<BR/>People have different styles and tastes, and some look really crazy.<BR/><BR/>5. A comment gives a web-page with some really cool projects and<BR/>asks whether that is possible in C. Most probably not. But ask your<BR/>students this: "Are Python lists lists or arrays?" and count how<BR/>many "Huh?" answers you get. Somehow,<BR/>I'm much more impressed by a student that can explain how a<BR/>program works however deep I go with the questions rather than<BR/>by one that rapidly writes code that draws nice trees. I'm not<BR/>saying that these projects were bad. On the contrary, as I said,<BR/>they seem really cool. But this attitude "it's either Python or C"<BR/>is quite bad. Students should know both.<BR/><BR/>Finally, here is THE reason for using nicely indented programs with<BR/>no explicit delimiters: That is how I write pseudocode on paper.<BR/>Well, that's MY reason.<BR/><BR/>Oh, sorry, one more thing. I think that the most basic skill for<BR/>programmers is to write simple programs that WORK and hence that<BR/>should be taught first. Proper indenting sounds like an advanced<BR/>topic by comparison.rgrighttps://www.blogger.com/profile/02991214367108471744noreply@blogger.com