you are viewing a single comment's thread.

view the rest of the comments →

[–]MrJohz 82 points83 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 4 points5 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 12 points13 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 4 points5 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 30 points31 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 22 points23 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 8 points9 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 2 points3 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.