Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Comparing Python to Java 8 and saying it’s more readable isn’t showing much.

And it’s not very portable the second dependencies with native code (which is common since pure Python is too inefficient for many tasks) are used.

I think Python is popular for two reasons:

- it’s believed to be beginner friendly compared to other languages. I’m not really sure why - maybe the whitespace?

- it has an enormous set of libraries available to use

In other words, Python has momentum. The language itself isn’t great, but that is a secondary concern to most, if they are even aware of this at all!



I started in Python, as a Biologist (hooray for Jupyter-lab, coding so visually, in small steps, with output just there is so great when starting to learn Python). I ventured into other languages every now and then. For example I tried to make an Android app in Kotlin that gets info from some API. I expect something like this but with more brackets everywhere:

    import request
   
    data = request.get(https://some.api/get_some_json)
    some_value_I_want = data['dig']['into']['nested_structure']
    
I didn't get it to work at all, I was lines and lines of code into the program when I didn't even get to see any returned values.

Also, say I want to make a nice plot of some tabular data (.tsv), I do:

    import pandas as pd
    import seaborn as sns
     
    data = pd.read_csv('some_file.tsv', sep='\t')
    pd.melt(data, value_vars=['s', 'max_vms'], id_vars=['sample', 'process', 'N'])
    g = sns.FacetGrid(data=data, col='process', row='variable', hue='sample', sharey=False, margin_titles=True)
    g.map(sns.barplot, 'sample', 'value', order=data['sample'].unique())
    
Boom, what a plot (or large grid of plots actually), so much information. Can anyone show me how to do this in some other language (but R)? Idk, maybe I'm just not so smart, I just learned to program at 35 after always being a biologist, but any venture into any language has me thinking: Why does this have to be so complicated?

(Btw, I'm putting 4 spaces in front of the code, why is it not rendered as code?)

When I just started I used Python to read, sort and transform images and output them to a PowerPoint file. One can use CSS like synthax to format the slides. Boom PPT with 120 slides with images and data from some Excel file that convinced a lot of people with a lot of data that fluorescent images next to H&E stains + metadata can be nice. Is it the best way to present such data? Meh. But man was it cool and easy and time saving.


This is just a property of having libraries. If you've got the same libraries in Java then the code looks identical except that you stick to word "var" in front of lines 4 and 6 and you don't have named arguments.

Python does have a great data processing ecosystem. But that isn't really a property of the language.


Creating a new venv, installing a few needed libraries that you know the names of with a simple command and writing a quick low-ceremony script that uses those libraries is frictionless in Python. Doing that repeatedly in nearly every other major language is not as easy.

Some languages have a good integrated tool chain (Rust, Go) but are not as approachable and forgiving.

Some are approachable but lack the friction-free story for locating and installing 3rd party dependencies.


The most similar language to Python is Ruby, not Rust or Go, and Ruby is better at the things you've listed. Which would bring us back to the previous point that it's not actually about ease of use.

Someone else identified Ruby's fatal flaw as not having good C tooling, and I think that's probably accurate.


Ruby has odd, once unique syntax that looks strange to anyone raised on C-like syntax, including js and java. Python is similar, simply removing redundant braces. So no ruby was not better at things most folks care about, i.e. being easy to learn.


You seem to have confused personal familiarity with ease of learning.


Things that are familiar are easier to learn, it’s a fact. As someone raised on math and English notation, then industry exposure. Ruby being a odd duck did it no favors.

Python definitely found footing based on its pseudocode readability. It’s gotten a bit worse recently with too many colons and features but already made it.


Poetry is indeed very nice for that. Bit of a learning curve but then very easy to push packages to PyPI or internal things like Artifactory.


Your examples don't depend on the language but on the libraries. You can be as simple and concise in most languages, provided the libraries let you, instead of needing to add boiler plate.

But what if your web request fails? Do you deal with it in time or use some_value_I_want which might contain junk?


I think you are confusing familiarity with ease of use.


This isn't really programming though. This is just calling out to seaborn and pandas with an unpleasant interface (Python).


Ok, then I'm not programming. Call it anything you want, I call it "Being productive." Or, "Saving on time spent clicking around in Excel." or "Automating the boring things." And I find it to be quite pleasant.

Maybe it also doesn't help that out there, in the C++, Rust, Javascript, Go world I'm going to run into people with usernames like "ihatepython".


Don't feed the trolls! Case in point, this is a quote:

quote_from_user_ihatepython == """ ihatepython 1 day ago | parent | context | prev | next [–] | on: Moscow Metro launches longest metro circle line

    You realize that the Nazis still exist and are Ukrainian, right?
"""


Sometimes I wish for "block" function in HN for such trolls (I really hope it's no-life troll working for 5 rubles per comment and not a real person with genuine hateful opinions like that).


This isn't really programming though.

It is however what a lot of people who 'program' at work do every day. Python actually lets working professionals solve real problems they actually have at work quicker and easier than any other programming language.


"That's not programming, that's just calling libc with an unpleasant interface"


Ironically, TFA claimed there are a bunch of people “not programming” in python getting real work done out there.

But, with a user name like that, I know I’m just wasting my time responding to you.


> - it’s believed to be beginner friendly compared to other languages. I’m not really sure why - maybe the whitespace?

I am leaning more towards it looking like pseudocode

> - it has an enormous set of libraries available to use

I believe that to be the actual reason. I've long held that python is a kinda bad language, but with FANTASTIC libraries


beginner programmers don't know pseudo code either though!

the best teaching language (imo) is one with few features or surprises. I think Scheme might come out top here.


I think Scheme might come out top here.

Depends what you are trying to teach. If you're trying to teach computer science and programming fundamentals, then sure. If you're trying to teach people how to get 'real work' done quickly and efficiently then Scheme will only get in the way and slow people down.

For example when I've taught programming, one of the tasks I taught fairly beginner programmers was to grab some satellite images between certain dates, try to detect if there is a forest fire, measure the spread of the fire and plot the spread on a map.

With python (and its excellent libraries) this is quite quick and easy, and most people are up and running and hacking around with their programs in pretty short order. They find it really cool and inspiring and makes them quickly realise that programming could be something useful in their day to day job. Trying to start with chapter 1 of SICP and Scheme and working up from there to solving the above problem would probably lead to most of these people giving up on programming very quickly. That being said the few people that made it all the way through that would no doubt be much much better programmers because of it.


> beginner programmers don't know pseudo code either though!

It looks like English. That's all pseudocode is, and they know that well enough.


And fantastic documentation!


This is an under-discussed point, at least from my biased opinion. It seems like the Python documentation ecosystem is the best, and has been building fantastic tooling for over 10 years now.


> but with FANTASTIC libraries written in C _and FORTRAN_

ftfy - it's the only way a tragically slow language like Python can keep up.

Edit: didn't forget FORTRAN


Eh, you massively overestimate the importance of performance.

For the vast majority of use cases, performance just isn't a priority. Doubly so for Python, that shines for simple automation, command line applications, and perhaps some serveless computing.

Being easy to write, having a good ecosystem of libraries, and being widely known is typically good enough. I wouldn't use Python to write a robust backend server side application, mostly because the language doesn't lend itself well for it.


Eh, you make incorrect assumptions about me. I'm stating a fact why Python is used - the data science ecosystem in Python thrives because of well-written libraries _written in C_ under the hood AND an easy-to-use language that writes like pseudocode.

If it was too slow, we'd be doing all of this in Java, the C# or maybe doing it in C/Fortran. But because of some early design decisions (Guido being on the matrix-sig helped), the history behind Numeric/Numarray and finally NumPy and SciPy being based on those efforts allowed it to thrive.


> it's the only way a tragically slow language like Python can keep up.

Those were your words, not mine. I need not make any assumptions.

I just replied listing use cases where Python shine due to its strengths, performance being mostly irrelevant. I didn't even mention data science.

And although it's beyond the point, if I was to use Python, why should I care in which language a library was written? If the language allows libraries written in other languages, this is actually a nice feature.


> If the language allows libraries written in other languages, this is actually a nice feature.

That’s actually my primary use case for python, playing with C/C++ libraries in a repl because they don’t natively have one.

Sure, it takes work to wrap a library but that’s something I enjoy doing.


libraries written in C

That is simply not true. Even libraries like numpy, scipy and scikit-learn are majority python code.


Majority python code, being ~60% is mostly wrapper code, with the slowest parts (the parts that matter) written in C.

https://stackoverflow.com/questions/1825857/how-much-of-nump...


Don't forget about FORTRAN


Does it matter?


Because it’s proof, PROOF!!!, that python is inferior to their favorite language.

Just wait until they learn the python interpreter is written in C… <grabs popcorn>


> - it’s believed to be beginner friendly compared to other languages. I’m not really sure why - maybe the whitespace?

Good bait. I'll take it.

- dynamic, weak (really "duck") typing, meaning users don't have to worry about conversion between things. Want to print() a dictionary of whatever? Sure!

- no semicolons to terminate a statement. End of line, that's it

- rich standard library, so you can actually get going on things without having to go on a quest to find the right library for your thing. JSON? It's right there. argument parsing? argparse. Http? http.client works...

- also yeah the "pseudocode" thing. Python is light on extraneous syntax.

Now eliti^H^H^H advanced programmers will frown on many of these same things that make it beginner-friendly...

Dynamic typing means that complex designs have to be careful with their APIs, lest you can get tangled up in deep type errors if you're not careful (I particularly hate the "mix-in" pattern). No semicolons mean, uh, long statements need to escaped? The standard library is "where lib go to die" because they can't evolve as much. "Significant whitespace!? What is this, COBOL!?!11"


Static typing had a tighter feedback loop - you don't even need to run the code to see you made a (type) error.

Ability to do structural printing of arbitrary structures is not restricted to dynamically typed languages.

However, I actually think a good beginner language could be dynamic or static.


> it’s believed to be beginner friendly compared to other languages. I’m not really sure why - maybe the whitespace?

Experienced programmers tend to forget how the experience was as a beginner programmer. But Python grew out of actual usability research into teaching programming to beginners. Logo is another language with the same background, but it never escaped that niche. The success of Python is because it attractive to beginners but remains a powerful tool as the programmer becomes more experienced.

Whitespace is definitely a factor - or rather the lack of redundant braces. Beginner programmer seem to really struggle with the lack of correspondence between the visual structure and the logical structure in most languages. Even experienced programmers get tripped up by erroneous indents. Python just solves this once and for all.

The lack of type annotations is also a factor. For beginners this is just an additional layer of complexity.

Scheme is great for teaching computer science students, but if you are just a regular Joe researcher wanting to get the job done, you want to write "2 + 2" like everybody else in the world, not "(+ 2 2)"

Most languages are designed to attract experienced programmers, e.g. by having C-like syntax which they may already be familiar with. But it has a cost for beginners.


The classic "public static void main" example is also getting old. It's been so long since I last wrote it, that I actually had to copy/paste it from the article. I just generate a new project from the "Spring initializer" plugin and jump straight into the real work.

If we want to measure developer productivity we should try to compare actual real world usage that goes beyond "hello world" using Notepad. The author did provide more examples in the article, but I think we should just retire the basic minimal hello world example for these types of discussions.

If their argument is that Python is simpler for quick scripts and programs, I agree. The same applies to ML / AI where Python has lots of great tools. Once you start looking at other areas (Django and FastAPI), there are many alternatives based on other languages where you can be just as productive.

Most of the time consuming work is spent doing business logic where the differences between languages doesn't matter as much. They all have advantages and disadvantages. Personally I prefer static typing for larger projects and teams.

If their argument is that Python is better in general, they need to provide better arguments.


A third point is that python is the default scripting and plugin language in a lot of popular commercial and professional applications. A lot of people I know who learned python did so to automate or extend applications they used for their 'real' work, like ArcGIS, FME, Rhino/Grasshopper, Revit/Dynamo etc.


Indeed. I wish Microsoft would push F# as the default macro language for Excel.


Python's biggest advantages are in my experience:

1. Near zero boilerplate. Python's boilerplate is usually no more than setting up a class and then calling a method. Often you can skip the class and just call it directly. This is probably the biggest strength; to give you an example, my standard test for a languages approachability is "how much work do I need to put in to get a very simple JSON file from a web URL" (nothing fancy like POST, just an HTTP GET). With python, a call to urllib.request.urlretrieve and then a call json.loads are all you need. In Java, you need to manually implement a bunch of boilerplate code that looks horrible, need to think about the size of your response in memory and often need to pass in configuration options that should be a case of "works by default" but aren't because the standard is ages old so it needs to be manually toggled on. Part of that is that the Java stdlib consists largely of reference implementations rather than actual implementations, which means that anyone who wants to implement something in Java will usually end up falling back to the stdlib interfaces, which in turn suffer from being stdlib interfaces, so a lot of "should really be on by default" expectations aren't on by default since the stdlib is where code goes to die, so you instead start piling on features.

2. Interop with C. I hold the opinion that C is a great language that doesn't work very well once you get to any form of scaling. Python allowing developers to take the slowest parts of their code and writing it in C to speed it up is one of the easiest speed gains to make and it avoids the biggest bumps that come with using C as your primary language in terms of project structuring.

3. Library support is as you say, good. If you need it, there's probably a package for it. Pypi is dependency-wise kind of a disaster but if you know how to set up requirements.txt, it works really well. Most libraries ship with "sane" defaults too.

All of these combine to a language that's easy to prototype, easy to expand

It's important to keep in mind that pythons biggest successes aren't in the speed-focused, low-memory environments where every speedgain is necessary. Its success lies in conventional desktops and servers, which have much more processing power and often have more leniency in being a bit slower.

With python you can write something in 3 hours what would take a day in another language, at the cost that instead of being lightning fast and done in 10 seconds, you need to wait 30 seconds. That's an issue for some environments but in 99% of the cases that's not a problem.

That isn't to say the language is perfect (no language is), but speed of development at the cost of slightly slower execution time is the main reason why python got popular.


>"how much work do I need to put in to get a very simple JSON file from a web URL" (nothing fancy like POST, just an HTTP GET). With python, a call to urllib.request.urlretrieve and then a call json.loads are all you need.

In C# you just have to do this: var things = await httpClient.GetFromJsonAsync<List<Thing>>("url");


why would an http client know anything about json? that's a bad code smell.


It doesn't. It's a standalone (static) helper method that uses HttpClient to perform the request and feeds the response body into a json parser. It's an extension method [0] which means that there's syntactic sugar so that you can write client.GetFromJsonAsync() and the compiler transforms it into the actual static method call, HttpClientJsonExtensions.GetFromJsonAsync(client).

0: https://learn.microsoft.com/en-us/dotnet/csharp/programming-...


Mostly because JSON is one of the most common formats used when sending over data. I think this practice started with pythons requests (which is my real answer as to what you should use in python but I wanted to focus on the stdlib), which has a json function on the Response object for convenience.

Most languages nowadays tend to implement some variation of this specific convenience because it's just one of the most frequently needed things; setting up a separate parser and then calling it might be the "cleaner" option, but it's also more boilerplate and the industry has largely moved to try and avoid that.


Java programmer, recently switched to using Python in the job - This exactly is it. Sane defaults is the killer feature of Python.


I agree comparing hello world code in Python and Java is a bit pointless. Hello worlds might be much shorter, but at scale, this becomes less relevant. Also, comparing to a language that hates change is unfair, if you compare it to C#, which is improving over time, you'll see the hello world also takes one line (but is 13 characters longer, so Python still wins!)


> if you compare it to C#, which is improving over time, you'll see the hello world also takes one line

Well yes it it does now, since C# 10 or, but in Python is have been a one liner since the beginning 30 years ago, and over the decades it has build a following. And even with recent efforts to cut down on boilerplate, C# still has more cryptic syntax than Python.

I'd argue C# is more maintainable in the long run due to the static typing, but there is no way it is as accessible to beginners.


> Comparing Python to Java 8 and saying it’s more readable isn’t showing much.

It shows an obvious reason why a lot of beginners choose python, even when learn Java basics in university first.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: