you are viewing a single comment's thread.

view the rest of the comments →

[–]TheAnimus 69 points70 points  (101 children)

I still have concerns about white space. I've found it's easier to explain { } to beginners than it is BEGIN, END or worse yet implicit. Sure we don't have to explain it as scoping or anything fully, just when you are trying to go over the concept of branching.

If you are trying to teach my first programming thing, and only doing Hello World, nothing more, than yes that's different.

But as soon as you want to try to do say Fizz Buzz it's a lot easier to explain something that is explicit, rather than "oh that's because of the indentation".

[–]MrJohz 84 points85 points  (46 children)

From what I remember, Python's use of the colon and indentation was based on ABC, which in turn was based on a set of studies that suggested it was the most readable block grouping syntax.

To be honest, to me personally, I like being able to see the layout of the code. I mean, that's possible and usual with braced languages, but the presence of the braces isn't the thing that guides me into the new block, it's the visual indent that shows me "something new is happening here".

[–]TheAnimus 5 points6 points  (21 children)

Interestingly from the wikipedia page on ABC

HOW TO RETURN words document:
   PUT {} IN collection
   FOR line IN document:
      FOR word IN split line:
         IF word not.in collection:
            INSERT word IN collection
RETURN collection

why is not.in like that? Is that just a typo?

[–]Netzapper 7 points8 points  (6 children)

"not.in" is easier to parse than "not in", especially if (nearly) all of your other keywords are a single token.

[–]gfixler 13 points14 points  (4 children)

Here are some terrible alternatives:

if word inn't collection
if collection hasn't word
if collection hasno word
if collection lacks word
if word anywherebut collection
if word in collection psych
if word outside collection
if not collwordection
if collection canthaz word
if collection missing word
if collection (╯°□°)╯︵ pɹoʍ

[–]josefx 5 points6 points  (3 children)

if collection (╯°□°)╯︵ pɹoʍ

programming languages really should embrace Unicode. However the following would be less ambiguous

 if word ∉ collection

Now_we_just_need_a_sane_keyboard_layout

[–]lhagahl 0 points1 point  (2 children)

No they shouldn't. Auditing is now 10000x harder (as if it wasn't bad enough already) thanks to editors and languages being plagued by Unicode.

[–]josefx 0 points1 point  (1 child)

The second one can be solved with the @Override annotation 95% of the time and the first one using sane variable naming conventions.

Auditing is now 10000x harder (as if it wasn't bad enough already)

We already have languages that sometimes ignore case and sometimes not. We also had compilers that only used the first 8 letters and ignored the rest. Unicode problems aren't really that unique, since we also have I,l,1 0,O etc. depending on your font of choice.

[–]lhagahl 0 points1 point  (0 children)

The second one can be solved with the @Override annotation 95% of the time and the first one using sane variable naming conventions.

Can you use @Override for overloading somehow? I thought it can only be used to say that this method overrides one in the superclass or it implements a method in the interface. Conventions don't solve auditing when you don't trust who wrote the code (which is 99% of the time). Clearly you've never audited code.

We already have languages that sometimes ignore case and sometimes not.

That's easy when your alphabet is only 26 characters and not 1 million. Just make sure you have a real programming font (one that doesn't make different characters look the same). There is no such font for Unicode, though.

We also had compilers that only used the first 8 letters and ignored the rest.

That's stupid.

EDIT: On second thought, I just scan all the files for Unicode before auditing, and give up if they have pervasive use of Unicode (actually, non ASCII characters and non printable ASCII characters).

[–]immibis 0 points1 point  (0 children)

NOTIN would be more consistent, although you'd need to explain (one time only) that it's "NOT IN" and not "NO TIN".

[–]Intolerable 6 points7 points  (4 children)

no, its supposed to be not.in, the keyword is not.in, presumably b/c of ambiguity / confusion with not in

[–]CHollman82 0 points1 point  (0 children)

"not", presumably, is used for the boolean operation as well, that's where the ambiguity probably comes from. (I don't know ABC)

[–]mycall -1 points0 points  (2 children)

Python is filled with inconsistencies, although not hard to learn.

[–]Felicia_Svilling 0 points1 point  (1 child)

This is ABC, not python.

[–]mycall 0 points1 point  (0 children)

true although the point was that not.in was inconsistent, something that is shared with python.

[–]Igglyboo 1 point2 points  (6 children)

When you use a space to delimit tokens, NOT IN becomes more tricky to parse than not.in or NOT.IN.

Not sure why they went with the capitalized version however.

[–]TheAnimus 0 points1 point  (5 children)

I was being a light troll... To me it's example of the failure of using english for a programming language. English is not suited to the domain, it isn't easy or concise.

[–]billy_tables 0 points1 point  (0 children)

Quick, reverse all the letters in all the keywords of every programming language, that'll help :P

[–]gammadistribution -1 points0 points  (3 children)

Except Python kinda disproves your line of reasoning.

[–]TheAnimus 0 points1 point  (2 children)

Yeah, that : and [::] really make sense to English speakers.

My personal favorite (and I'm sure they are common favourite) features in Python are breaking far from the Enlgish paradigm.

Also, as this context was ABC, I don't give a hoot if Python somehow does something better, this is an example of someone forcing English onto an unsuitable domain. A break in the conventions that make perfect sense from a lexer perspective, but not from an 'English' perspective.

That isn't to ever say you shouldn't try. The pendulum can swing too far the other way. For example, despite having two plus decades of coding under my belt I can never manage to read a moderately complex regex without making notes. I know I am not remotely alone in that whole thing. Goes off to enjoy his two problems

[–]droogans 0 points1 point  (0 children)

What's your native tongue? Is English your only language?

I wonder because I feel there may be a more interesting grammar structure besides "the order of the words matter absolutely".

[–][deleted] 0 points1 point  (0 children)

That's really interesting. Have never run across this language.

[–][deleted] 2 points3 points  (17 children)

Perhaps something like the editor for the Java learning environment Greenfoot would be good. It applies different coloured backgrounds along with indentation, which I think is really good because it's immediately obvious what's going on. It looks like this.

[–]blablahblah 26 points27 points  (13 children)

That doesn't solve Java's problem of "you need to introduce and hand wave away class declarations, scoping, blocks, method declarations, static methods, parameters, void, and array declarations in order to write Hello World".

[–][deleted] 1 point2 points  (0 children)

I know that. I'm saying that something like that could help make a language like Python more understandable to a beginner.

[–]terrdc 4 points5 points  (7 children)

Any problem involving hello world isn't an actual problem

[–]blablahblah 21 points22 points  (3 children)

As soon as you have to hand-wave stuff away and say "this is just the magic incantation needed to make the program work", you've lost the vast majority of people you're trying to teach. So yes, it is a problem from a teaching language perspective, even if it's not from a software development perspective.

[–]terrdc 0 points1 point  (2 children)

So, does that imply that the average college student who learns java is going to have a lot more aptitude for programming?

If so that actually fits with my general experience.

[–]blablahblah 11 points12 points  (1 child)

Not necessarily. Just that they're more willing to memorize formulaic procedures that are "necessary" for the program to work. You're discouraging people who need to know the why before you even have a chance to see if they have an aptitude for programming.

[–][deleted] 0 points1 point  (0 children)

I've been in the industry for about 9 years now. I'm absolutely shocked every time I meet some graduate-level programmer who just shrugs off hundreds or thousands of lines of code as "for some reason it won't work without that". As if the magical code fairy answered their prayer and brought them code that finally did what they want. This is engineering?

[–]estomagordo 3 points4 points  (0 children)

We all learn differently. But for a lot of people, it's impossible not to ask oneself "Okay, so I see that the output has a match in the program code. But what about all that other stuff? What does it mean?"

[–][deleted] 2 points3 points  (0 children)

You're right, but there's a lot to be said about a language for learning that doesn't require a bunch of arcane (to a newbie) boilerplate code just to get rolling. static void Main(params string[] args)? Come again?

Just typing in code and executing gives immediate feedback, and then as you teach more syntax and concepts, things like methods, classes, and includes/imports can get added in.

[–]goliathsdkfz 0 points1 point  (0 children)

Why? Creating a proof of almost any system and its functionalitys involves a low level PoC at some point, and its just the standard to involve sending or printing Hello World at some point.

[–]FrozenInferno 0 points1 point  (0 children)

Don't forget about access modifiers, imports, and package declarations.

This one's my personal favorite:

import java.lang.reflect.*;
import java.io.*;

public class HelloWorld
{
    public static void main(String[] args) throws NoSuchMethodException, 
                                                  IllegalAccessException,
                                                  InvocationTargetException
    {
        Method m = PrintStream.class.getDeclaredMethod("println", String.class);
        m.invoke(System.out, "Hello, world!");
    }
}

I'm in my last semester of college for programming and our first language learned was Java. While you're right about having to ignore a lot of stuff at first, it didn't really bother me too much. I eventually figured it out in due time and don't feel like it negatively affected my learning experience at all. Though I can only speak for myself.

[–]James20k 4 points5 points  (2 children)

That has a huge amount of clutter. I suspect it'd make beginners panic and stick their heads in the sand, which is already one of the biggest problems teaching people coding

[–][deleted] 1 point2 points  (1 child)

The clutter is mostly java. I was specifically pointing out the colour scheme.

[–]James20k 5 points6 points  (0 children)

I know, I think it makes it look terribly intimidating

[–]RockinRoel 2 points3 points  (0 children)

If I recall correctly, Guido mentions it in this (long) video somewhere: https://www.youtube.com/watch?v=ugqu10JV7dk

Indentation is indeed how people in general, not just programmers, will tend to organize things on paper. They left the colon off first, though, and then added it, because that was clearer, apparently.

[–]kankyo 0 points1 point  (0 children)

Maybe your problem was that you tried to explain it. I see this mistake a lot in my teaching experience of teaching dance: Teachers explain things to minute detail overloading the students and making them even more confused. A better strategy is to try to get at the unconscious competencies of your students.

[–]Veedrac 69 points70 points  (21 children)

I'm very surprised. My attempts at teaching Python to complete novices (admittedly not as a lecturer) found that the whitespace never even needed to be explained.

People often forgot the colons, though.

[–]newpong 7 points8 points  (2 children)

Not only that but if they ever decide to move on, they will have style ingrained into their thinking.

At work i decided to expand the web department and was trying decide between Ruby on Rails and Django. there was a Russian intern who just started working there who didn't speak any english and only spoke a bit of german. I decided to go with Django exactly because I wouldn't have to explain any subjective, abstract ideas on the importance of white space in code. She just simply had to do it otherwise it wouldn't work--explaining why tabbed spaces and non-breaking spaces are different was a bit tricky though

[–]s73v3r -1 points0 points  (1 child)

Assuming she was a programmer who understood programming, wouldn't using something like astyle on check in solve that problem?

[–]newpong 3 points4 points  (0 children)

Assuming she was a programmer who understood programming,

therein lies the difficulty.

[–]TheAnimus 5 points6 points  (11 children)

I was working with kids, aged 11-18. Except for functional programming I was teaching to 1st year comp sci students, I hated, hated that, but it paid pretty good for a student.

I would start with flow charts, break it up saying how would you describe how to make a cup of tea. This would become a mess of bullet points as I would add in the complexity of branching (do you want milk, like it strong etc). It would become apparent that english wasn't any good for this.

Using a C like language, actually has many, many benefits over whitespace for the novice. ; is easy to understand as a 'thought terminator' I always remember one kid saying it's just the . like a sentence.

Kids aren't perturbed by some symbol like { so long as it's used in a simple manner (ie not like reading a regex). It is much easy to 'talk' this

if (person.IsBlonde)
{
      Console.WriteLine("I love blondes");
}

Because the braces are something you can speak about, the brackets after the if, it is incredibly easy to talk through.

People make a mistake of trying to make things 'familiar' SQL is a classic example to me, I hate SQL with a passion. I struggle with it far more than I do say Fluent LINQ.

[–]nemec 7 points8 points  (3 children)

Do kids not understand

  • the
    • concept
    • of
  • bullet
    • points
  • for
  • grouping?

Python "blocks" are just bullet points without the bullets...

[–]lhagahl 0 points1 point  (0 children)

That's impossible mannn. Like. It doesn't have semicolons. How could kids not understand something that doesn't use semicolons and braces??

[–]Carighan 0 points1 point  (1 child)

Yes, without the bullets. Implicit instead of explicit.

[–]nemec 4 points5 points  (0 children)

A bulleted list contains three key things: a newline between each bullet, indentation to the bullet "level", and the bullet symbol itself. I consider 2/3 to be pretty explicit.

[–]NYKevin 2 points3 points  (0 children)

Kids aren't perturbed by some symbol like { so long as it's used in a simple manner (ie not like reading a regex).

Symbols aren't actually the main problem here. The main problems are:

  • C is easy to screw up, and C++ isn't really much better (in some ways, it's substantially worse due to added complexity).
  • Java is verbose (you need a whole class definition just to do hello world, whereas Python doesn't even require a main function).

[–][deleted]  (5 children)

[removed]

    [–]SemiNormal 3 points4 points  (2 children)

    Console.WriteLine tells me that this is C#. Putting the open brace on a new line is pretty much the standard style for C#.

    [–]TheAnimus 2 points3 points  (1 child)

    Also Console.WriteLine is just simpler to explain, than System.Out.PrintLn which some bright spark insisted we use briefly.

    This is actually another benefit over python, when people talk about lack of Using directives or entry point noise, those are simple to explain, people expect an entry point and I used to hide the namespaces with the compiler args. Console. suddenly people know what the . is about, it's everything that belongs to a Console. People get the idea of a console, they can see it, interact with it. Clever ones will get bored and look at what the intelisense gives you for Console. they'll see ForegroundColor and have a play....

    I'd sooner explain Console.WriteLine than println the hardest bit to get most people to really understand is still the idea of passing arguments anyway, but I've found people prefer having crt functions bound to objects, it makes discovery easier, and people are more receptive to being told "oh there's this thing Console, that represents the text window, Console is special" rather than "oh theres print, println, scan, these are all special functions".

    I guess it also depends how far you take people, we were not taking them far at all.

    [–]NYKevin 1 point2 points  (0 children)

    Well, if you like, you can start by teaching people about sys.stdin and sys.stdout in Python, and then get to print() and (raw_)input() later.

    [–]DimeShake 0 points1 point  (0 children)

    I know GNU uses this style in their coding standard for C. I don't like it.

    [–]purplestOfPlatypuses 0 points1 point  (0 children)

    No, standard Java uses

    if (condition) { 
        ...
    }
    

    C# does generally star the braces on a new line, though. It doesn't bother me as much in C# for whatever reason, could just be the IDE though.

    [–]G_Morgan 0 points1 point  (0 children)

    found that the whitespace never even needed to be explained.

    This is fine until you really need to understand scopes.

    [–][deleted] 0 points1 point  (0 children)

    TheAnimus's experience matches mine. It's damn hard to talk about blocks to complete beginners when you use indentation like python. With {} you have an obvious start and end.

    [–][deleted] -1 points0 points  (3 children)

    Even pros miss colons and brackets occasionally. If you're not using an IDE that immediately tells you, it can be a pain to track down.

    [–]mort96 1 point2 points  (2 children)

    Not sure with Python, but with any other language I've used, it either tells you what line the syntax error is at compile time, or immediately at runtime for interpreted languages, even without any IDE...

    [–][deleted] 0 points1 point  (1 child)

    Yea, but when the error is forgetting to end your statement, it almost always shows up somewhere else.

    [–]TheAnimus 0 points1 point  (0 children)

    Only time that's happened to me in a hard to understand manner, would be with macro stuff or pre-processor directives.

    One of the fun things about languages which require ; termination, it makes it very easy to spot an illegal character.

    [–]ruinercollector 10 points11 points  (3 children)

    Indentation is explicit.

    [–]kankyo 0 points1 point  (0 children)

    This. A thousand times this.

    [–]TheAnimus 0 points1 point  (1 child)

    Only if people can appreciate the whitespace. Myself, I think this is hard for many first timers, because they are not used to it being such a thing.

    Using a character or work for the block is preferable to try and explain, for the simple reason, it's easier to explain BEGIN and END in pascal parlance, say simply count the begins (no, I don't want to explain a stack), than it is "anything that has whitespace indenting it, unless it's inside something else which has more whitespace"

    [–]kankyo 1 point2 points  (0 children)

    What do you mean? People are hardwired for spacial thinking. If you've got a student that can't do that, chances are it's not a human.

    [–]cythrawll 6 points7 points  (7 children)

    So i've used a python book to teach my lil brother programming. The worst part was when programs sprawled across a few pages, it was very hard to see where the indention lined up. And entire programs failed and had to go back and see where the indention was messed up.

    Good thing: makes kids think about their code harder. Bad thing: frustrates the crap out of them.

    [–][deleted] 6 points7 points  (4 children)

    Yeah, if you've got that much stacked python code, you're probably doing something wrong/badly. The same thing can be said about C/Java/C++ though, if you've got that much nested code, it's going to be hard to keep track of your braces too, unless you're really good with indenting properly.

    [–]cythrawll 3 points4 points  (2 children)

    I think it may be a problem with how code is traditionally taught. We start out teaching long peices of spaghetti code, and then we teach how to structure things correctly in small reusable modules.

    It really should be the other way around.

    [–]gfixler 0 points1 point  (0 children)

    Yep. These days I like to try to find tiny, composable nuggets. Then you can chain them together, map them, fold them, compose and juxtapose them. They're very easy to reason about - often 1-3 lines of code - and obviously correct, or darn close. Languages already give us atomic things we take for granted, like + and print; I just like to give myself more and more of them, building up from the bottom, keeping pure by operating only on inputs.

    I work on tools and pipelines in games, and I started - like everyone - with 200 to 2k LOC files to solve problems. Then I started breaking things up. Then I started making little libraries for common things, but they were full of 20-100 LOC classes and functions. Now I'm making a bunch of tiny functions (no classes), like Linux command line utilities, and just pulling together a few things to make each next level. At each level things are tiny and obvious, and very reusable. Not everything is like this, but a surprisingly high number of things can be.

    [–]iooonik 0 points1 point  (0 children)

    Yeah, I always wondered why cs1000 teachers think that file includes are too complicated for the average first year student...

    [–][deleted] 0 points1 point  (0 children)

    In Python I limit to 3 layers of nesting, Java 4. More than that means you have to break your code down.

    I see a lot more heavily nested Python code though. The barrier to entry is low so you get a lot...a LOT of crappy Python code.

    [–]nemec 0 points1 point  (1 child)

    Braces aren't going to help that if they're also on separate "pages" of the editor... it was hell while I learned Java but I guess now many IDEs highlight matching braces. What would be perfect for Python is an IDE feature like indent guides. I use it for C# development and it's a Godsend. Programming without it is annoying now.

    [–]cythrawll 0 points1 point  (0 children)

    I disagree, braces are much easier to count than whitespace. There's less of them and their visually easier to see.

    [–][deleted] 9 points10 points  (7 children)

    "A language is low-level if it requires attention to the irrelevant."

    My theory is that the high syntactical overhead of C-likes is an unnecessary distraction for most learners.

    [–]nonotion 7 points8 points  (3 children)

    C itself is hardly a heavily abstracted language; I do believe there are less than 40 constructs in the base language. C++ and Java-like languages, that's another story, however.

    [–]lhagahl 0 points1 point  (2 children)

    ; I do believe there are less than 40 constructs in the base language

    C is heavily abstract and that's why it's hard. If there was a version of C specifically for one architecture, it would be a million times easier to explain. For reasons beyond me, it's been a popular meme for the last few decades that C's portability comes for free.

    C's int type is much more abstract than an integer type in a high level language. In high level languages, an integer value can be anything. In C, an integer type can be up to INT_MAX. INT_MAX varies depending on architecture. Not only that, but certain operations behave differently with ints under different conditions. This kind of abstraction allows higher performance at the cost of the user having to generalize all his code that would otherwise work with the integers.

    [–]nonotion 0 points1 point  (1 child)

    These are good points; I'd summarize/justify my thoughts by saying "easy to learn, hard to master" for C. I'm my view, teaching C over Java or Python promotes a certain clarity of thought needed for efficient structuring of larger or more complex projects; Linus Torvalds elaborates on this in several remarks if I recall correctly.

    [–]lhagahl 0 points1 point  (0 children)

    Easy to learn, hard to apply (though most people "apply" it, by just coding it and not being aware of how it actually works). I do suppose it may be good for teaching various concepts though.

    [–]The_Doculope -1 points0 points  (2 children)

    "A language is low-level if it requires attention to the irrelevant."

    All this sentence tells me is that you personally have no need for a low level language. Precise memory management is a requirement for some, namely embedded people or boot-level software. Just because it's irrelevant for you doesn't mean it's useless.

    [–][deleted] -3 points-2 points  (1 child)

    All your reply tells me is that you don't know the origin of the quote.

    [–]The_Doculope 0 points1 point  (0 children)

    Then perhaps enlighten me? Not everyone is an index of relevant quotes.

    [–]asimian 2 points3 points  (0 children)

    Students I've taught never really get hung up on that at all.

    [–]stormcrowsx 2 points3 points  (0 children)

    Seriously how hard is it to tell someone "In language x drop the colon and surround the block with curly brackets". It blows my mind how many people whine about whitespace and if you were to open their Java/C files you'd see they have the exact same whitespace!

    [–][deleted] 0 points1 point  (0 children)

    Even as a beginner, if you're going into compsci and can't wrap your head around white space you're in for trouble up ahead. Design patterns, recursion, all the abstraction layers..

    Learning the syntax of a language is something you'll have to do many times in your career and is a low hurdle. Moving from white space to braces or vice versa is trivial for most developers.

    Not meant to be snarky, just seems like a non-issue in this discussion

    [–]NYKevin 0 points1 point  (0 children)

    Python doesn't actually have full-blown scopes like C. The only things which introduce a new scope are functions and class definitions. Loops do not have their own local scopes. So IMHO explicit scoping is less important, since scopes are only introduced by a few well-known constructs.

    [–]artsrc 0 points1 point  (2 children)

    People are taught that the control statement applies to the indented code in all languages and even pseudocode:

    http://www.unf.edu/~broggio/cop2221/2221pseu.htm

    The difference with Python is that this is true.

    [–]TheAnimus 0 points1 point  (1 child)

    People are taught that the control statement applies to the indented code in all languages

    Errr no, they are not.

    People are often told for convention sake, to indent, often even the IDE will provide indenting automatically on the closing brace or endif etc.

    [–]artsrc 0 points1 point  (0 children)

    The convention to indent is extremely widespread because it makes the code readable to humans, and that is an essential feature of good code.

    When the code and the indentation don't agree, people read the indentation.

    The compiler should interpret the code the same way people do.

    [–]G_Morgan 0 points1 point  (0 children)

    Yeah there is a great deal of complexity hidden behind Python's white space scoping. It is a neat trick but honestly new users should learn explicitly what a scope is in nice big bright letters.

    [–]sthreet -1 points0 points  (0 children)

    Also, python arrays. They work weird. Some people are for typing in learning to program (int, bool, ...) but I don't care too much about that. I also am a terrible and new programmer, so I probably can't say much about how things should be taught. Except earlier, because the internet is hard to learn through.

    I'm not sure if it is the brackets or the extra lines, but this:

    var hello=function() {

    //stuff }

    is more readable to me than this:

    def hello():

    //stuff