News for hackers. Stuff that matters.
Re:Why Is Python Growing So Quickly? by alienreborn on Thursday September 14, 2017 @12:28PM (#15249578)
because readability is one of the most, if not the most, important quality for mainstream programming language adoption.
Re:Why Is Python Growing So Quickly? by mark-r on Thursday September 14, 2017 @12:36PM (#15249668)
As much grief as Python gets for significant whitespace, I think it really helps the readability. Not only does it enforce what should already be good indenting habits, but it eliminates the noise of braces.
Re:Why Is Python Growing So Quickly? by dbcurtis on Thursday September 14, 2017 @01:13PM (#15250109)
I've always had the opinion that computers should serve the needs of humans, not the other way around.

In languages where white space is insignificant, it is pretty much universal that we use syntactic elements to communicate block structure to the compiler, and white space to communicate block structure to humans. Having two different ways of communicating block structure is: a) redundant and wasteful, and b) a source of bugs.

So, if you buy into the idea that having two different ways of communicating block structure is somewhere between an annoyance and a language design defect, and also buy into the idea that computers should serve the needs of humans, then it follows that the compiler should extract block structure from source the same way that humans do. That being: significant white space.

The {} languages seem very primitive to me any more.

Re:Why Is Python Growing So Quickly? by qquark on Thursday September 14, 2017 @02:45PM (#15251161)
You could argue, using the same logic, that when using {} languages, the computer can serve you by automatically doing the indentation anyway. This is the case in practice: I never have to worry about indenting my code in C, as support for that in most editors is great.

{} languages have the advantage of allowing you an immediate restyling of the code when the original author (who can be of varying skill level) wrote something you don't like looking at, or when you want to change the style of your own code for various reasons.

I find that Python-style blocks generally cause me more mild annoyances than {} blocks. A frequent thing that happens is copy-pasting/moving a line from some place to another with a different depth: In C, I paste and run my automatic indentation, while in python I have to specify manually by how much I want to indent my new code so that it can know within which block I want it. ... And it's not like you could do so automatically: if I want to paste something after the code of an "if ...:" block, the editor cannot know if I want it inside or outside the block.

On a more abstract level, I personally prefer a language where the end of a block is explicitly specified by the presence of a visible character rather than by the absence of an (arguably) invisible one, and where the form of the code does not affect its function in any way...

I'm not trying to argue that much against the python logic though, because the potential for disastrous style is indeed limited, it has its specific advantages, but I don't think delimiter-based languages can be qualified as more primitive just because of this.

Re:Why Is Python Growing So Quickly? by dbcurtis on Thursday September 14, 2017 @02:58PM (#15251325)
I agree that modern tooling largely erases the tedium of getting indentation right. Whether C++ or Python, selecting a block and hitting either tab or shift-tab fixes indentation. (Which beats the heck out of re-indenting on punch cards, which I'm old enough to have used for CS homeworks...)

And, yes, it is hard to argue that presence of {} makes a language objectively more primitive, which is why I used the word "feel"... the syntactic sugar necessary to keep the block structure straight just looks like noise to me any more. But as with many things, it comes down to personal preferences.

Re:Why Is Python Growing So Quickly? by newen on Thursday September 14, 2017 @04:42PM (#15252337)
I find that the amount of bugs I tend to get when I copy-paste code far outweighs any potential aesthetic pleasure I get from seeing no begin-end block identifiers. Also, I don't want to let python have credit for not having those block identifiers because python has the colon begin identifier, which is completely redundant.
Re:Why Is Python Growing So Quickly? by wickawic on Thursday September 14, 2017 @12:51PM (#15249863)
I always figured the people complaining about the whitespace thing are people whose code I really don't want to be reading anyway
Re:Why Is Python Growing So Quickly? by reificator on Thursday September 14, 2017 @02:14PM (#15250838)
Why is that?

My code has whitespace that reasonably closely matches Python's rules regardless of the language. I only say "reasonably closely" because I don't spend enough time in Python to really be sure about any potential gotchas.

But like PEP 20 says:

> Explicit is better than implicit.

Brackets are explicit. Whitespace is implicit.

Re:Why Is Python Growing So Quickly? by kevinmgranger on Thursday September 14, 2017 @02:21PM (#15250917)
Indentation is explicit.
Re:Why Is Python Growing So Quickly? by reificator on Thursday September 14, 2017 @02:44PM (#15251150)
Indentation is implicit, because you can't see the characters that cause it without turning on whitespace rendering. You only can tell it's there by either moving the cursor around or by observing gaps between characters and other characters or characters and the left margin.

And the end of a block, the lack of indentation that denotes that, is absolutely implicit.

Re:Why Is Python Growing So Quickly? by runevault on Thursday September 14, 2017 @01:55PM (#15250623)
The problem isn't whitespace period, its that if you aren't careful the significant whitespace can bite you, for example people sometimes accidentally mix tabs and spaces, which can get... ugly.

Personally I prefer {} blocks so I don't have to know what sort of white space is creating the indentation, even though I do miss using python sometimes and may come back to it for the right project.

Re:Why Is Python Growing So Quickly? by redblacktree on Thursday September 14, 2017 @02:48PM (#15251192)
> accidentally mix tabs and spaces, which can get... ugly.

This is trivially solved. You can find and replace with sed[0] if you want to be fancy, or just use your favorite text editor/IDE. The teams I've worked on have never had a problem with this. There is always an established convention in a project, and if you're breaking the convention -- e.g. because you prefer tabs -- you're doing it wrong, just by virtue of breaking the convention. If your project is new and you need to set a convention, do that. (also, PEP8 recommends spaces, so there is an authority to reference as a tie-breaker)

[0]: something like: find ./ -type f -exec sed -i -e 's/ / . /g' {} \;

Re:Why Is Python Growing So Quickly? by devrandomguy on Thursday September 14, 2017 @06:26PM (#15252997)
Furthermore, there is no need for anyone to care what spacing scheme their team uses, after configuring their editor on day 1 with that team. I have Vim convert Python code to tab indentation when opening files, and have it convert to 4-spaces indentation when saving a Python code file. No one should be wasting even a flicker of brain activity over indentation in the 21st century, regardless of how backwards everyone else's preferences are.

While you're at it, please also s/\s+$//g on save. Those unintentional trailing spaces really clutter up Git history, and that comprehensive, clean history is what enables the team leads to do their job without bugging you on Slack. It also signals carelessness, or at least a lack of care for personal tools, and has your name attached to it.

Re:Why Is Python Growing So Quickly? by ubernostrum on Thursday September 14, 2017 @04:30PM (#15252240)
people sometimes accidentally mix tabs and spaces

I just tried with three different editors, and literally could not manage to get code in a file indented with a mix of tabs and spaces despite actively attempting to. Who are your co-workers who actually personally have had this happen to them in, say, this decade (not nebulous stories from the internet of "I heard once about this"), and how did they do it?

Re:Why Is Python Growing So Quickly? by runevault on Thursday September 14, 2017 @09:40PM (#15253936)
I know I ran into it at one point, but I haven't slung python in anger in like a decade, so maybe the editors most people are using have started preventing this sort of thing better.

Though I do know in Visual Studio (what I do my day to day coding in these days) I've had situations at work where tabs and spaces got mixed together and at some point it finally started complaining but not right away.

Re:Why Is Python Growing So Quickly? by blunte on Thursday September 14, 2017 @01:07PM (#15250056)
Lack of braces is visually appealing, but I really miss brace hopping in Vi - % to bounce between open and close brace. That also applies to languages with do/end instead of braces.
Re:Why Is Python Growing So Quickly? by mark-r on Thursday September 14, 2017 @01:11PM (#15250085)
Good point, I use that feature in C++ quite a bit. But I find that my Python programs tend to use smaller blocks, I don't know if it's just because I'm solving smaller problems or because it's easier to break things down in Python.
Re:Why Is Python Growing So Quickly? by ufmace on Thursday September 14, 2017 @04:54PM (#15252438)
I've had mixed feelings about it, but I think one of the better things about it is that it forces less experienced scientist and data analysis programmers to use consistent whitespace.
Re:Why Is Python Growing So Quickly? by agumonkey on Thursday September 14, 2017 @12:53PM (#15249896)
It does cut a large chunk of issues off. Also helps "canonicalize" idioms. That said you can still have mess from time to time. But that's alright.
Re:Why Is Python Growing So Quickly? by pyre on Thursday September 14, 2017 @12:35PM (#15249661)
But significant whitespace means that I can't write code like this:

   sub (@) { return map { "@{[ $_[0] . $_ ]}" } @$_ };

Disclaimer: The majority of the programmers that I have known in real life that have a significant (and very vocal) dislike of Python's whitespace requirements have all written code like that above (this is my from-memory reproduction of actual code that one of them wrote). Python sucks because it's "restricting" them from being "expressive" with their code.
Re:Why Is Python Growing So Quickly? by wyldfire on Thursday September 14, 2017 @02:18PM (#15250880)
Phew -- it's an automatic filter.

Sadly, you can write code just like that in Python. I don't know what that perl snippet does, my caches have long since flushed ;) -- but here's a Python snippet that's relatively dense:

   def foo(y): return lambda x: {str(i) : '_{}'.format(i**y) for i in range(x)}
Re:Why Is Python Growing So Quickly? by minimaxir on Thursday September 14, 2017 @12:40PM (#15249727)
For statistical programming in particular, readability of your code by others is the most important part of the coding style.
Re:Why Is Python Growing So Quickly? by BurningFrog on Thursday September 14, 2017 @12:51PM (#15249877)
That's absolutely true of any programming.
Re:Why Is Python Growing So Quickly? by neuronexmachina on Thursday September 14, 2017 @01:07PM (#15250049)
Yep. An order of magnitude more time is spent reading and maintaining a line of code than is spent writing it. Readability adds a tiny amount of time to the writing, but makes reading and maintainability so much better.
Re:Why Is Python Growing So Quickly? by lilbobbytables on Thursday September 14, 2017 @12:40PM (#15249728)
Glad I read your disclaimer before responding. :P

Was just reviewing colleague's code with them the other day. Hit some blocks like this (not quite as offensive, but tackling a bit in one line), and hell if they knew what was going on in their own code.

Re:Why Is Python Growing So Quickly? by reificator on Thursday September 14, 2017 @02:38PM (#15251078)
I've never posted about whitespace sensitivity before today, so maybe I don't fit in the group you're pointing at, but I don't like Python's whitespace sensitivity either.

Not because I want to write everything on one line, but because it's an extra step when trying to understand what code does.

For instance, a piece of code is misbehaving, not being called as part of the block it visually appears part of. In a bracket/paren language I can highlight one bracket and my editor shows which one matches. In Python I have to figure out what the indentation is built from, spaces or tabs, and make sure there's no ambiguity there.

We have developers here that are claiming they wrote things in Python for their PHD, and yet when I look at their code in any language there are tabs and spaces mixed in the same line, with inconsistent indentation. Multiple people have tried to express the issue or teach ways to deal with it, to no avail.

The fact of the matter is that whitespace is by definition invisible, and that makes it hard for people to grasp its importance. Basing control flow on invisible characters is asking for trouble.

To quote PEP 20:

> Explicit is better than implicit.

Brackets are explicit, whitespace is implicit. You only can see whitespace by the gaps between visible characters, and then you have to guess. Is it an actual U+0020 like you see 99% of the time? Is it an nbsp? It it a tab that happens to stop after the width of a space? You don't know until you encounter an error or turn on whitespace rendering.

Was it copied and pasted from www.python-help-7575.com, which uses a platform that favors punctuation spaces? Was it copied from a site that didn't wrap their code in <code> or <pre>? (I see this all the time in comment systems on programming blogs) Should we claim that copying and pasting code in a beginner targeted language is something you do at your own risk?

Re:Why Is Python Growing So Quickly? by jplatte on Thursday September 14, 2017 @03:33PM (#15251736)
> In Python I have to figure out what the indentation is built from, spaces or tabs, and make sure there's no ambiguity there.

The following program throws a TabError in Python 3:

  def demo():
  	print("1 tab")
          print("8 spaces")
It does work in Python 2, but I'm pretty sure the majority of developers have 4 space wide tabs by now, meaning they won't be able to mix tabs and spaces in Python 2 code either.

EDIT: So Hacker News has code blocks, but doesn't strip the indentation that is required to introduce them. So you'll have to lead the 2 leading spaces in each line if you want to try this out for yourself.

Re:Why Is Python Growing So Quickly? by reificator on Thursday September 14, 2017 @04:51PM (#15252407)
> So Hacker News has code blocks, but doesn't strip the indentation that is required to introduce them. So you'll have to lead the 2 leading spaces in each line if you want to try this out for yourself.

Your example is good, but the technical issues experienced in posting your example are perfect.

Re:Why Is Python Growing So Quickly? by seanmcdirmid on Thursday September 14, 2017 @12:43PM (#15249767)
Alternative syntax for short one liner functions (e.g. As recently added to C#, always in scala) can reduce a lot of this friction without sacrificing formatting guidelines. However, I'm not sure if it's in python's philosophy to explore such things.
Re:Why Is Python Growing So Quickly? by someone1012 on Thursday September 14, 2017 @12:58PM (#15249955)
Have you ever looked e.g. at the distutils code or tried to figure out how to use it without using Stackoverflow?

That function is easy to parse if you take 20 min learning the syntax. Object oriented monstrosities aren't.

Re:Why Is Python Growing So Quickly? by AlexCoventry on Thursday September 14, 2017 @12:40PM (#15249736)
What does that do?
Re:Why Is Python Growing So Quickly? by falsedan on Thursday September 14, 2017 @01:17PM (#15250143)
So let's break it down:

    sub
It's an anonymous sub

    (@)
It has a prototype that says it accepts a list of arguments (this is the default in perl though).

Prototypes are mostly for giving hints to the compiler on how to unambiguously parse calls to your function later. For an anonymous sub, it's pointless because you assign its value to a variable, and then brackets are required when calling it.

    return
It returns the result of the map (this default in perl is to return the result of the last expression & everything is an expression though)

    map
same as python map(code, list)

    { "@{[ <some stuff> ]}" }
This is a particular perl goof for interpolating array lookups into a string. Usually, perl's sigils let variables be interpolated without any issue, but since we're using $_[0] to use the first element of the @_ array, it's ambiguous with $_ . '[0]'.

The @{} dereferences the contents of the braces as an array, and [] creates a new arrayref. The arrayref has one element, and perl's default stringification of an array (join them all with no separator) means that it… iterpolates the thing inside the @{[]} into the surrounding string.

This is pointless though, since it's the only thing in the string. The author might have been trying to give a string context to force stringification of the thing, but the dot operator already provides that context.

    $_[0] . $_
This is a string of the first element of … hmm. Not of the currently-mapped element (that's $_). $_[0] refers to the first element of @_. This makes a new value which is the concatenation of the first element with the current element.

    @$_
This is a short way of writing @{ $_ }: dereference the arrayref that's stored in $_. But $_ is not set anywhere, so I assume this is a typo of @_

I would have written this as:

    my $prefixer = sub { my($prefix , @rest) = @_; return map { $prefix.$_ } @_ };
And it would work like this:

    say $prefixer->('Hi_', 1, 'str', 7);
    > 'Hi_Hi_Hi_1Hi_strHi_7'
The 'best' way to write it would have been:

    sub { $_[0].join($_[0], @_) }
Re:Why Is Python Growing So Quickly? by falsedan on Thursday September 14, 2017 @01:22PM (#15250214)
The python equivalent is

    lambda *lst: ''.join([str(lst[0]), str(lst[0]).join([str(_) for _ in lst])])
Which is uh… begging for an initial line of "lst = map(str, lst)"
Re:Why Is Python Growing So Quickly? by RodgerTheGreat on Friday September 15, 2017 @11:55AM (#15258159)
If I follow correctly, the equivalent in K would be

    {,/(*t),/:t:$x}
Flatten (,/) the first element of the list (*t) joined with each element of the list (a,/:b), where t is the input x cast to a list of strings (t:$x). Curly braces make the expression an anonymous function, and since no argument names are specified explicitly the name x is the single input argument.
Re:Why Is Python Growing So Quickly? by falsedan on Friday September 15, 2017 @05:34AM (#15255793)
A more idiomatic solution:

    lambda *lst: ''.join(['{}{}'.format(lst[0], _) for _ in lst])
Re:Why Is Python Growing So Quickly? by AlexCoventry on Thursday September 14, 2017 @02:02PM (#15250715)
Wow, that was a journey. Thanks.
Re:Why Is Python Growing So Quickly? by jwilk on Thursday September 14, 2017 @01:13PM (#15250113)
It's syntactically correct, but pretty much nonsensical.

(I guess the original code did something useful and looked very similar to this.)

Re:Why Is Python Growing So Quickly? by Alex3917 on Thursday September 14, 2017 @01:36PM (#15250381)
With Python even the code I wrote as a junior developer basically stands up five years later, looking back as a senior developer. There are definitely things I would have done differently, but there isn't any code where it would take several weeks just to figure out what the hell was going on and then another several weeks to make some modest improvements.
Re:Why Is Python Growing So Quickly? by acomjean on Thursday September 14, 2017 @12:39PM (#15249721)
While better than perl, as someone who has to maintain others python code the tendency to want to write stuff compactly makes it difficult to maintain than other languages in my opinion (the 5 others I work with). I've found other languages easier to read.

It might just be the code base I'm working with..

Re:Why Is Python Growing So Quickly? by kodablah on Thursday September 14, 2017 @12:45PM (#15249793)
I think there are two forms of readability: localized readability and whole-program readability. Python only satisfies the former. Your statement about readability being one of the most important qualities I believe is true, but more for whole-program readability in my experience.
Re:Why Is Python Growing So Quickly? by JoeMalt on Thursday September 14, 2017 @01:12PM (#15250107)
Agreed. Working on a large Python codebase, I find myself greatly missing Java's improved static analysis, even for simple things like "find the definition of this function".
Re:Why Is Python Growing So Quickly? by andybak on Thursday September 14, 2017 @01:22PM (#15250205)
If you aren't ideologically opposed to the use of an IDE then PyCharm solves this for the vast majority of cases. I get ~90% of the editor functionality I'd get in a statically typed language in PyCharm. Automated refactors and all that jazz...
Re:Why Is Python Growing So Quickly? by tw1010 on Thursday September 14, 2017 @12:36PM (#15249675)
Why do us engineers have a tendency to oversimplify everything to one big major cause like this? I see it all the time. Obviously in this case this is not the only reason. The real reason is a mix of many influences.
Re:Why Is Python Growing So Quickly? by cremp on Thursday September 14, 2017 @12:35PM (#15249648)
Golang forces readability; might want to give it a shot.
Re:Why Is Python Growing So Quickly? by lilbobbytables on Thursday September 14, 2017 @12:42PM (#15249755)
Just the other day I started looking back into Golang. Syntactically, and with Gofmt, it is quite readable.

But then they have to go and ruin it by making single letter variables a common thing.