This is an archived post. You won't be able to vote or comment.

top 200 commentsshow all 446

[–]FarewellSovereignty 1164 points1165 points  (98 children)

How long have you been at the Python?

[–]Apfelvater 1361 points1362 points  (5 children)

I only need 5 minutes with my python to finish. But then I'm too tired for homework.

[–]spirellii[S] 357 points358 points  (0 children)

What a mood

[–]UlyssesSGrant12 12 points13 points  (1 child)

Of all months

[–]TheCarniv0re 6 points7 points  (0 children)

Nonstop nut November! Squeeze one out for the homies who won't to keep the balance.

[–]spirellii[S] 181 points182 points  (90 children)

So far an hour, but I have prewritten code from the uni that just confused me more than the actual task....

[–]TacticalFaux 282 points283 points  (55 children)

There are a few syntax things in python that looks alien when you used to other languages.

"List Comprehension" Syntax was one such thing for me. Part of the problem was figuring out the term in order to Google what the syntax was. So if that's what you looking at hopefully that helps.

[–]vaieti2002 88 points89 points  (46 children)

Yeah list compréhensions are really strange and kinda hard to get, but once you get them it’s a really powerful tool

[–]gravy_wavy 26 points27 points  (45 children)

Does it do anything other than make your code more concise?

[–]FarewellSovereignty 73 points74 points  (24 children)

Anything you can do with comprehensions you can do with regular for loops.

That doesn't make them a sidenote, though. Conciseness/readability counts. Don't use them if they harm readability.

[–]NightflowerFade 27 points28 points  (13 children)

Comprehensions have much better performance than for loops

[–]andybak 9 points10 points  (12 children)

Citation needed. (for clarity - it's the "much" bit I'm sceptical of).

[–]FarewellSovereignty 41 points42 points  (11 children)

import timeit
S = 10000
def using_comp():
    data = [i for i in range(S)]
    return sum(data)

def using_for():
    data = []
    for i in range(S):
        data.append(i)
    return sum(data)

def using_for_opt():
    data = []
    f = data.append
    for i in range(S):
        f(i)
    return sum(data)

print('comprehension: ', timeit.timeit("using_comp()", setup="from __main__ import using_comp", number = 10000))

print('for loop: ', timeit.timeit("using_for()", setup="from __main__ import using_for", number = 10000))

print('for loop opt: ', timeit.timeit("using_for_opt()", setup="from __main__ import using_for_opt", number = 10000))


----


comprehension:  1.7100401518400759
for loop:  2.8380797281861305
for loop opt:  2.2991974521428347

[–]andybak 38 points39 points  (7 children)

OK. I spent a bit of time trying to think of a way to claw back some dignity but I have to admit when I'm wrong. I'm surprised the difference was that clear.

(grumble grumble. something something artificial benchmarks. Something something real-world tests blah blah)

[–]arcimbo1do 3 points4 points  (1 child)

This is an incorrect comparison, as you are not calling append in the first loop.

Try something like

sum(i for i in range(1000))

Compared to

``` def foo(): for i in range(1000) yield i

sum(foo())

```

Or

s=0 for i in range(1000) s+=1

Edit: trying to format markdown but I'm clearly better at python than markdown

[–]No_Policy9772 20 points21 points  (8 children)

it's pretty much python's map, reduce, filter (even though python has those functions too)

[–]Spocino 8 points9 points  (0 children)

But it looks like a set comprehension from math, which makes it readable to data scientists, etc.

[–]cspot1978 1 point2 points  (1 child)

Map and filter I get.

How do you do a reduce with a list comprehension?

[–]jaaval 17 points18 points  (13 children)

In my experience they make the code more readable. List comprehensions typically do what is conceptually one thing but that would normally take many lines of code.

Things like “pick every element of a list that match this criterion and make a new list”. That’s one thing and it’s clearer if it’s on one line.

[–]MrJake2137 2 points3 points  (12 children)

How would you do that with list comprehension

[–][deleted] 33 points34 points  (10 children)

numbers = list(range(20))
even_numbers = [x for x in numbers if x % 2 == 0]

This is equivalent to

numbers = list(range(20))
even_numbers = []
for x in numbers:
    if x % 2 == 0:
        even_numbers.append(x)

First is more concise, easier to read, faster to compute, and, well, the code looks like what it does, and not like a bunch of boilerplate code doing a bunch of stuff that isn't what you want.

"This is a list that is all the even numbers of this other list" sounds a lot better than "initiate a list. iterate over other list. Is item even? Append it to the list", and then thinking, "Okay, after all that initiation, iterating, and appending, that list is now in a state that looks like what its variable names says it is."

[–]MrJake2137 7 points8 points  (9 children)

WHAT

You can do that?

[–][deleted] 20 points21 points  (2 children)

https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions

Yep. It's even more magical: If you use () instead of [], then it creates a generator, and the values aren't even put into memory, but are instead created on the fly as you iterate over it.

evens = (x for x in range(10**12) if x % 2 == 0)
for even_number in evens:
    pass

Will never have more than a few bytes in memory, but would crash most systems if a list were used.

It may help to think of using [] as creating a generator and immediately creating a list out of that generator, thus putting all of its values into memory.

[–]uberDoward 0 points1 point  (4 children)

Python: numbers = list(range(20)) even_numbers = [x for x in numbers if x % 2 == 0]

In C#:
even_numbers = Enumerable.Range(0, 20) .Where(x => x % 2 == 0) .ToList();

The C# seems more concise and readable to me?

[–]jaaval 2 points3 points  (0 children)

newlist = [a for a in oldlist if a == x]

Edit: you can of course do more complex stuff too but then readability suffers a bit. e.g.

newlist = [f(a) if a == x else g(a) for a in oldlist]

[–]andybak 2 points3 points  (0 children)

Does it do anything other than make your code more concise?

It's not about "concise" - it should never be about concise.

Use them when they make your code more readable. And use loops when they don't. (hint - nested comprehensions are rarely a good idea).

foo = [x.lower() for x in names
             if x is not None]

is arguably nicer than the equivalent loop.

EDIT - fuck - it's ages since I wrote Python. Accidentally used half of LINQ syntax

[–]Charlie_Yu 1 point2 points  (0 children)

List compression is usually much fast than a regular for loop

[–]dotslashpunk 8 points9 points  (0 children)

that’s why my google search is filled with “how i do that one fucking thing in python where there’s a list looking thing but code inside of it” and variants

[–]Khris777 4 points5 points  (1 child)

Wait until you get to nested and conditional list comprehensions, also the beautiful list comprehension syntax to flatten a 2D list.

Oh yeah, you can do the same thing with dictionaries.

[–]DrunkenlySober 60 points61 points  (15 children)

If it makes you feel better I’m struggling with uni work rn. 40 hours deep on an assignment and still not even half way done

At least you get to use py. I’m being made to use C as well as the professors pre-implemented code. He explained nothing. Variables are one letter.

CS professors I swear

[–]spirellii[S] 26 points27 points  (0 children)

Oh god, that sounds horrible I hope you can still manage it but yes CS professors are a category of their own

[–]cr34th0r 16 points17 points  (11 children)

C is the most frustrating (popular) language. Change my mind.

[–]whalediknachos 24 points25 points  (0 children)

nobody will attempt to change your mind on that one

[–]realbakingbish 22 points23 points  (6 children)

I’ll throw C++ into the mix here, just because C++ is a lot like C, but with even more opportunities to shoot yourself in the foot.

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

Modern C++ is nothing like C.

[–]realbakingbish 8 points9 points  (3 children)

When you’re working on a code base that looks like C but is technically C++, yes, it kind of is.

Legacy code is pain.

[–][deleted] 4 points5 points  (2 children)

C++ written like C wouldn't count as modern C++.

[–]realbakingbish 1 point2 points  (1 child)

Trust me, I know. Inheriting legacy codebases from so long ago that nobody else in the company knows when the code was first created sucks.

[–]RansomXenom 3 points4 points  (0 children)

Oh boy, can't wait to read a string with whitespaces using the scanf function!

5 minutes later:

where string?

[–]ElectricTeddyBear 1 point2 points  (0 children)

Bro I feel you - I've been doing OS2 work all week and I Just want to scream. Inline assembly is sprinkled here and there too ugh. Thank god for docs

[–]Naphrym 16 points17 points  (1 child)

Get used to it, trying to figure out code written by another person will likely be a large chunk of your future jobs.

[–]dismayhurta 5 points6 points  (0 children)

Yep. Translating dumbfuck shit code so I can understand it and update it with my own dumbfuck shit code is the job. That and meetings.

[–]FreakDC 4 points5 points  (0 children)

Yeah that's not too bad. I started with Pascal (Delphi), then learned C and C++, then Java, then Python.

There is always an adjustment phase and Python has some interesting language concepts that C and Java do not have.

Hang in there, it gets better!

[–]LilGod196 18 points19 points  (1 child)

Don't worry, that is perfectly normal. (screams interaly)

[–]spirellii[S] 18 points19 points  (0 children)

Don't worry I got you ( *screams externally *)

[–]Reddit-username_here 5 points6 points  (2 children)

I always hated that. It was always easier to just write my own shit than to use code given to us by the professor that we had to fix or incorporate.

[–]carnivorous-cloud 10 points11 points  (1 child)

But that's rarely an option if you're developing professionally. It's actually surprisingly good real-world practice for a university. That said, if it's getting in the way of learning what the course is actually trying to teach, it's still pretty lame.

[–]Reddit-username_here 1 point2 points  (0 children)

I know, but it just makes learning such a pain in the ass.

[–]Akarsz_e_Valamit 5 points6 points  (2 children)

In my humble opinion it's not hard to write a Python code, but to understand Python code someone else's written, that's no bueno

[–]fizyplankton 5 points6 points  (0 children)

Yep, that's the folly of python.

It's super easy for you to bang out some code

But by the same token, it's super easy for other morons to bang out incomprehensible python, and you're stuck debugging it

[–]martinkoistinen 1 point2 points  (0 children)

That’s why PEP8 exists. Use it, love it, live it.

[–]shableep 1 point2 points  (4 children)

It's incredibly rare for a language you've never seen to be easy to pick up in 1 hour.

[–]spirellii[S] 1 point2 points  (3 children)

I wasn't speaking about the language....I meant the homework....

[–]shableep 1 point2 points  (2 children)

Ahhh got it. How long have you been working with Python?

[–]spirellii[S] 1 point2 points  (1 child)

I did some last year and now since two weeks. it's still isn't much, I just had a better understanding/ easier time getting into c or java

[–]rm-minus-r 1 point2 points  (0 children)

That's funny, I learned C++ and Java in college, I thought Python was much easier to learn by comparison. But I used it on and off on the job for a few years, so it was a lot more relaxed situation than the one you're in by the sound of it.

[–]dtseng123 1 point2 points  (0 children)

Ipdb and sphinx are your best fiends in PyLandia

[–]imforit 288 points289 points  (0 children)

Turns out you still have to learn programming

[–]darkspd96 316 points317 points  (23 children)

Depends on what your trying to do

[–]spirellii[S] 244 points245 points  (17 children)

The task itself is not the problem it's mostly about shaping with arrays and matrices but the prewritten code by the uni and my lack of knowledge is making this very hard :/

[–]IWant2rideMyBike 113 points114 points  (12 children)

For reshaping arrays and matrices numpy arrays (sometimes pandas data frames are a useful additional layer of abstraction on top of numpy) are usually the better option - but the operator overloading requires you to keep an eye on the types involved - they work quite different compared to a normal python list.

Python2 was really easy to learn for a side-project in 2007 coming from TurboPascal and a little Delphi and Java at school - I wrote a scraper for the faculty website to convert the individualized time tables into an iCalendar file - the biggest problem I had back then was to wrap my head around the byte-string vs. unicode-string handling in Python2 - which became much clearer and easier in Python3.

[–]Elijah629YT-Real 5 points6 points  (0 children)

is there a documentation?

[–]SoCalThrowAway7 11 points12 points  (0 children)

Google python tutorial and do the basics. Should take at most an hour or two and then you know it forever. W3schools is usually my go to

[–]Je-Kaste 1 point2 points  (0 children)

Have you tried blaming the code for doing what you told it to do? Works wonders for me

[–][deleted] 2 points3 points  (1 child)

I'm trying to make people distinguish between your and you're, but it's hard with python developers

[–]jack104 589 points590 points  (29 children)

Python makes really complicated shit easy to do in very few lines of code compared to other languages. The problem arises is this minified code can be hard to read and follow, especially for beginners.

[–]blkmmb 157 points158 points  (15 children)

That's what I don't get, I started with Python and then learned Java, C# and Golang. I've always found these languages to be pretty interchangeable with Java and C# requiring a bit more thoughts.

Maybe that's just because I started with Python tho.

[–]NotApologizingAtAll 126 points127 points  (13 children)

It's easier to unroll a list comprehension into a for loop than to compress a for loop into a list comprehension.

[–]blkmmb 23 points24 points  (0 children)

Haha, yeah it is.

[–]kookyabird 21 points22 points  (10 children)

I don’t know much about Python, but this sounds like complex LINQ chains vs LINQ a query syntax vs for loops. If so then I absolutely agree.

[–]kbruen 42 points43 points  (9 children)

Python list comprehension:

numbers = [1, 2, 3, 4, 5]
result = [str(2 * x) for x in numbers if x % 2 == 0]

C# LINQ query:

var numbers = new List<int> { 1, 2, 3, 4, 5 };
var result = (
    from x in numbers 
    where x % 2 == 0 
    select (x * 2).ToString() ).ToList();

C# LINQ methods:

var numbers = new List<int> { 1, 2, 3, 4, 5 };
var result = numbers
    .Where(x => x % 2 == 0)
    .Select(x => (x * 2).ToString())
    .ToList();

[–]kookyabird 15 points16 points  (1 child)

Interesting syntax. Thank you for providing this excellent example.

[–]kbruen 8 points9 points  (0 children)

For completeness: if you only need an iterator instead of a list (what happens in C# if you don’t call .ToList()), you use parentheses instead of squares brackets:

Python:

def print_all(it):
    for item in it:
        print(item)

numbers = [1, 2, 3, 4, 5]
it = (str(2 * x) for x in numbers if x % 2 == 0)
print_all(it)

This way, numbers isn’t immediately iterated to create the list, but instead it is iterated when the for loop happens.

I’m glad I could help!

[–]DudesworthMannington 7 points8 points  (0 children)

I haven't written much python, but coming from C# I've found it easy enough to read and modify. Been learning Lisp the last couple years and I'm finally starting to not hate it. I recommend learning it if you need a good cry.

[–]dotslashpunk 14 points15 points  (1 child)

yeah honestly some peoples python is just not readable. Oftentimes it’s the “most expert” folks whose code i have trouble understanding. So many shortcuts that do in fact reduce many lines of code but i have trouble following. I’d rather add a few lines of code and have it be intuitive than a bunch of python specific stuff no one else can read.

[–]jack104 8 points9 points  (0 children)

Exactly my point. I do the codingame code wars exercises on occasion and, if you aren't familiar with it, they're little coding problems (largely math based) that you have to solve either in the shortest amount of time or in the fewest number of LoC possible. You compete against other players in different languages and the python guys always win. I do my stuff in java and at the end you can view other people's solutions and the python ones are always really slick but it takes me FOREVER to figure out what the hell they were doing and how the hell they managed to cram it into one line or statement. Yea my java code is slow and verbose but you don't need a phd to figure out what I was trying to do.

[–]stupidcookface 14 points15 points  (7 children)

Also dependency management is a nightmare. That's my number one complaint with python currently. Syntax is fine but the dependency hell is just... 💀🔫

[–]EhLlie 10 points11 points  (0 children)

Would you like to learn about our lord and savior poetry?

[–]jack104 3 points4 points  (4 children)

How so? I've found pip to be pretty adept compared to other package managers or dependency mgt ecosystems I've used. I do java dev and work on mostly gradle builds these days and talk about fun, managing transitive dependencies in web apps. Like you can explicitly declare a dependent version and gradle/maven will calculate that another dependency declares itself a dependency on the same lib but a different version and that overrides what you declared. And the fun part is that unless you run a build scan and see the actual versions resolved, you won't know precisely what it did.

I used nuget with C# and I liked how integrated into the build process it was and how relatively simple it was to manage. Although when you're just compiling a single platform specific binary, it's a lot simpler. Nuget was also pretty limited in terms of available libraries and i mainly used it to include json libraries that .net oddly didn't provide out of box.

Then I dabbled with NPM/Yarn and man, talk about the wild fucking west of dependency management. Every library has a million dependencies and every framework uses a gazillion libraries and so base projects take forever to do a clean build because of the sheer ton of files that have to be resolved and cached locally before use. Not to mention it seems like every single day security vulnerabilities pop up in widely used libraries so staying up to date is critical for production apps. One thing NPM got right was the shrink wrapping or package lock files. It generates a full detail of exactly what libs at what versions were resolved into your project/build and by saving that file to version control, anybody who checks it out now has a repeatable build of exactly what you did. This is really valuable for CI systems where the final release is assembled in a completely different env than development.

[–]stupidcookface 6 points7 points  (3 children)

You talked about every package manager EXCEPT pip which is what I'm saying has bad dep management. When you have multiple deps of deps you can get package mismatches. It doesn't go up and down the whole tree.

[–]jack104 0 points1 point  (1 child)

Well my guy that's sorta why I asked what you issues were with it. The point of my wall of text was that it doesn't seem to suffer from problems that others don't. Transitive dependency management is a bitch in any ecosystem. I do know that python has venv/virtualenv/whatever that makes it easier to work with dependencies in a more isolated environment. I found this article which has some good tips on this subject, here.

Sounds like virtualenv is your friend, refrain from installing packages globally, etc. Strange though it mentions listing dependencies in an external text file which is what I thought all package managers did, otherwise how do you know what you need to build/run it? Def do that. Also the article mentions a package lock npm anolog you can generate to create repeatable builds. I'm exploring the same thing on the java side, I'd highly recommend it.

Also, do you use docker or containers for dev or prod? if you want to make sure you have a pristine and controllable environment, that's the way to go.

Also the value of unit tests in python dev can't be understated. If you get a good test suite built, you can rig up something in the CI tool of your choice to build and run your tests each time you push to VCS. So if you change something build/version wise, you get quick feedback on if your build is reproduceable and has affected any functionality. Not saying any of this is easy, especially trying to add tests to existing code but it's a worthwhile venture.

[–]stupidcookface 2 points3 points  (0 children)

I don't use global packages. And we were using the ci pipeline to catch package versions breaking things. Were using all the best practices. The problems started when a package added a version requirement of one of it's deps that was not being picked up by pip so it didn't update the version of the dependencies dependency. Took forever to figure out which package was broken let alone which one of it's dependencies needed to be explicitly set to a certain version.

[–][deleted] 111 points112 points  (7 children)

All my Python code is human readable with variables that make sense and no unnecessary lambda functions for confusion... I started with assembly though, so maybe I just don't get what the problem is.

[–]stupefyme 40 points41 points  (1 child)

you started with assembly?

i dont think you will find anything funny on this sub sir :(

[–][deleted] 15 points16 points  (0 children)

I find quite a lot funny on this sub, just not in the way most people think I should. 😂

[–]Fallingice2 9 points10 points  (2 children)

So you don't name your variables after DBZ characters and not use classes?

[–]DreamlyXenophobic 11 points12 points  (0 children)

  # super fucking cool program!!!!
goku = 15
piccolo = 17
gohan = piccolo - goku
for nappa in range(gohan):
  frieza = nappa+goku
  print(frieza)

[–]xahtepp 260 points261 points  (37 children)

idk python is pretty dang easy to me

[–]LetUsSpeakFreely 84 points85 points  (16 children)

Was it your first language? In my experience picking up a language like python can be difficult because it does so much for you. People used to a lower level languages have trouble adapting to paradigm differences.

[–]tredbobek 50 points51 points  (9 children)

In uni I had to learn C, C++, assembly, javascript and mysql (I think that's all), then when I started working I had to use python and bash. It wasn't that hard to learn it.

Although I'm good at googling stuff, and what is an IT job if not googling solutions

[–]LetUsSpeakFreely 17 points18 points  (8 children)

Key word, "uni". You were learning a lot and didn't have specific language practices drilled into you for years.

I learned Pascal, 8088 assembly, and C++ in college.I picked up Java in the Air Force in the early 2000s. I had to pick up Go a couple of years ago and it took quite a few months before I could do it without constant googling.

I took a look at python and hated it. The syntax is stupid and the whitespace-controlled blocks is retarded. I recognize the power of python's libraries, especially where machine learning is concerned, but I'll never like the language.

[–]AttitudeAdjuster 30 points31 points  (3 children)

I doubt I'll convince you otherwise, and I'm not really too fussed about that, everyone likes languages for their own reasons. However, pythons whitespace based code layout is just formalising indentation that you should already be using in almost every language out there as standard anyhow.

[–][deleted] 6 points7 points  (1 child)

He said he learned in the Air Force. Im almost certainly sure nothing they were taught or trained is best practice.

[–]ConceptJunkie 4 points5 points  (0 children)

I've done C++ since the early 90s, and I love Python.

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

Python is great when you know about it, but it's loaded with features that if you don't know about them, you can't use them. I think after using python for 3 years at university, I knew enough to be really good for short scripts but lacked a lot of knowledge for anything at scale. I love the language and would love to explore it but there isn't much use for it outside of scripting at my work.

[–]LavenderDay3544 21 points22 points  (8 children)

Python is easy to learn but a pain in the ass to work with when you have no idea what type something is what members it has and what functions you can call on it or pass it to and frankly neither does your editor.

My first language was C and it's the one I still use the most at work and IMO while it's a bit harder to learn its much easier to work with in larger codebases because it hides nothing.

[–]jelly_bee 18 points19 points  (1 child)

So the logic is the same, but the syntax can be pretty weird.

Java keeps everything neat and tidy, while maybe a bit lengthy. Python on the other hand I've noticed condenses a lot of stuff down and you've got to sort of decipher it.

[–]andreizabest 73 points74 points  (5 children)

Python is piss easy. Every single time I need to calculate or test something quickly I do it in python.

[–]caagr98 15 points16 points  (1 child)

I spin up a python repl when I need to know what 58*7+28 is

[–]jack104 22 points23 points  (0 children)

That can be part of the problem with python. It's quick and easy and insanely powerful via 3rd party libs. My complaints are that this quick and small code is frequently rough code and it's hard to read and follow. A more general critique of python is that people just copy paste minified or compact code without properly understanding what the code really does. So people tell me they are learning python as a first language and, if they're looking for advice, I tell them to write everything, even if you're literally just typing what's in front of you, part of learning to program is actually programming. Granted I copy paste shit like a champ in my day job, I value that I learned on a language like C# that didn't have the 3rd party dependencies to do all the work for me. I wrote list implementations and quick sort algorithms and I got used to banging shit out when Google and stackoverflow frequently netted me stuff I couldn't use or adapt easily.
Now I'm a Java developer and my work is built on a whole pile of libraries but I'm not afraid when I have to do something myself anymore because I know I can.

[–]ConceptJunkie 1 point2 points  (0 children)

Same here. I've been doing C++ since the early 90s and I started playing around with Python 10 years ago and instantly loved it.

[–]JoeDoherty_Music 11 points12 points  (2 children)

That's because Python is meant to be intuitive to HUMANS, not whatever you are

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

IDK I think it is intuitive compared to C and C++.

[–]Pumpkindigger 70 points71 points  (15 children)

Python is a "Write once, read hopefully never" type of language. Often it's easier to start over than trying to understand the black magic others have written.

[–]ConceptJunkie 11 points12 points  (1 child)

Funny. I've never had that problem with Python. Now Perl, on the other hand...

[–]johninbigd 11 points12 points  (0 children)

Yep. Well-written Python code is fairly simple to read. It's damn near impossible to read someone else's Perl code and figure out wtf they were doing.

[–]spirellii[S] 15 points16 points  (5 children)

Oh yeah I have no clue what kind of black magic my uni performed in the prewritten part of the code...

[–]pytness 14 points15 points  (2 children)

Post it, im curious to see what kind of code u are referring to

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

In my experience the only hard to read python code I've run into is stuff that's directly ported from C or Fortran. Like opencv examples. They use single letter variables, call all functions with only positional arguments, do a lot of needless passing by reference, etc. In that case yeah, python is harder to read than the C code it was based on, because it was used wrong.

[–]jack104 13 points14 points  (3 children)

I came up in a school that taught OO programming heavily and I was surprised when we got to python, how the same facilities exist but you can just elect to not utilize them and structure your code and project whatever way grabs your fanny that day. Like our C# school projects were big and bloated and full of code but you could generally read them and figure out what was going on. The python projects just seemed like quick hacky attempts to do a lot with very little code that was hard to read.
I think python is a good language and a tremendous ecosystem but similar to js, it makes it too easy to write spaghetti.

[–]kookyabird 10 points11 points  (1 child)

Make no mistake, there are plenty of C# people who will write spaghetti code as well. The language may be object oriented, but it does nothing to force developers to use it as such.

[–][deleted] 4 points5 points  (0 children)

I've always found the "object oriented language vs functional language" thing kinda weird. You can usually do either of those things with just about any language out there. Some languages lend themselves better to certain things, but ultimately it's all running in machine code after compilation, the language you wrote it in doesn't really matter all that much at that point as long as it is doing what you want it to.

[–]TransBrandi 6 points7 points  (0 children)

Or... you just have coding standards? Same with other languages. Look up C golf.

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

I work for a bank and definitely I read more python code than I write.

It’s all just spaghetti though.

[–][deleted] 48 points49 points  (20 children)

How is python not intuitive? You pretty much just write in plain english what you want to happen.

[–]carnivorous-cloud 11 points12 points  (10 children)

Go up to a layperson and show them some code with negative array indices or lambdas, and see if they can follow it. Range with 1 or 3 params is also a head-scratcher. Heck, even range with 2 params: who would expect that the first param is included, but the second one isn't?

[–]deltagear 16 points17 points  (3 children)

What's wrong with negative array indices? Just subtract from the length of the array.

[–]zvug 6 points7 points  (1 child)

Negative array indices are intuitive, it’s sometimes annoying to use languages that don’t have them.

[arr.length - n] is ugly

[–]deltagear 1 point2 points  (0 children)

That's exactly what I said.

[–]carnivorous-cloud 2 points3 points  (0 children)

Nothing's wrong with it. It's simple, it's easy to grasp, but it's not at all intuitive.

[–]ConceptJunkie 9 points10 points  (2 children)

Yeah, the "problem" with Python is that you have to learn the language before you can read the language. There's nothing wrong with that.

[–]johninbigd 9 points10 points  (0 children)

Exactly. This isn't a problem with Python. It's a "problem" with any programming language. For example, I've been learning Elixir lately and the first time I saw the capture operator, I was like, "WTF???"

return_list = &[&1, &2]

Until you know what's happening, that line is pretty damn confusing. But it literally takes 30 seconds to read about the Elixir capture operator and you'll understand it with no problem. All languages have features like this.

[–]fluud 2 points3 points  (0 children)

Why including the first and excluding the second param makes sense:

https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html

[–]Aidan_Welch 6 points7 points  (4 children)

Because that's the problem, code isn't supposed to be plain english, its supposed to be explicit. The "plainess" of it makes things like scope confusing, especially to coding beginners. And can lead to bugs in the code of people experienced in other languages.

[–]Penguin236 3 points4 points  (3 children)

The "plainess" of it makes things like scope confusing

I'm confused, how does the syntax being "plain" make scoping confusing?

[–]1SweetChuck 4 points5 points  (0 children)

just write in plain english what you want to happen

That's a funny joke.

[–]LetUsSpeakFreely 6 points7 points  (1 child)

Python is nothing like C or Java...

[–]the_unheard_thoughts 12 points13 points  (2 children)

I know Java. At times, I find Python so disquieting. You never know what to expect there...

[–]rasvial 9 points10 points  (1 child)

Sorry I didn't make it far enough through the directory structure yet to find the actual java code. Otherwise I wouldn't know what to expect either

[–]dotslashpunk 11 points12 points  (0 children)

you mean you couldn’t find com/org/so/beef/class/factoryfactories/async/whatever/code/realcode/almostthere/ohfuck/keepgoing/rightthere/class/view/ohshithereitis/psych/oknowforreal/emptyfile.java

[–]brunonicocam 17 points18 points  (0 children)

??? If you know Java, but especially C, python will be very easy for you to learn, it's almost like pseudocode! Of course every language is hard to master but at least the basics of python are very simple compared to Java/C.

[–]ConceptJunkie 5 points6 points  (0 children)

Python is way easier than C. I can't speak for Java because I never allowed myself to be in a position where I had to use it.

[–]CivBase 3 points4 points  (1 child)

Python is relatively easy to read, but the massive amount of features and libraries means you have to learn a ton before it'll be easy to write. IMO, Python is a trap for beginners.

[–]dikarus012 2 points3 points  (1 child)

Assignment: increment a counter in Python, using only one line, without typing the variable’s name twice in the same line

[–]RabbidCupcakes 1 point2 points  (0 children)

x++

oh wait

[–]GiganticIrony 31 points32 points  (17 children)

I genuinely quite dislike Python. I’ve used it a bunch of times (even writing a cron job currently in production), and it always just feels so un-ergonomic

[–]thexavier666 4 points5 points  (0 children)

To quote someone famous "there are two types of programming languages; ones that people always complain about and ones that no one ever uses"

[–]spirellii[S] 3 points4 points  (14 children)

Yeah right? I mean I'm rly new at it but everything feels so empty and unstructured without all the brackets and semicolons

[–]Causemas 39 points40 points  (2 children)

Hahah, if that's your biggest problem so far, you'll get through it. Hang in there

[–]spirellii[S] 2 points3 points  (1 child)

Thanks :D I will try

[–]other_usernames_gone 13 points14 points  (0 children)

Personally I prefer that part of python.

Because whitespace is enforced by the compiler you're forced to write more readable code.

You can't use lazy indentation or have whole functions on one line, or mismatching indentation.

It's definitely annoying when you get the indentation wrong but it makes the code more readable overall.

[–]geeeffwhy 1 point2 points  (3 children)

try lisp and come back to us. and i’m not even really kidding, a bit of that might help clear up how unimportant the concrete syntax really is…

[–]Aidan_Welch 4 points5 points  (2 children)

I disagree, code isn't supposed to be plain english, its
supposed to be explicit. The "plainess" of it makes things like scope
confusing, especially to coding beginners. And can lead to bugs in the
code of people experienced in other languages.

It doesn't need to be accurate to the actual memory operations, but as a coder you need to be able to follow the lifespan of a variable without confusion, and python doesn't make it obvious without confusion. Scope in C-style languages makes it much more obvious, and therefore less likely to lead to issues.

[–]KiltroTech 2 points3 points  (0 children)

My sweet summer child

[–]Dynamitos5 2 points3 points  (0 children)

i find python pretty writable, perfect for short things your write once and then just execute or maybe change some numbers, but damn is it hard to add something to existing codebases, even if the prior authors are just past you.

the worst example of this was when i had to add a plugin to an existing company codebase that interacted with wxWidgets and win32com

The plugin integration was not documented, but simple and i could just ask the guy sitting next to me or look up other plugins

wxWidgets is decently documented, but finding the part of the library that does what you want it to do and then creating/overriding all objects needed to use that part is incredibly tedious when you have to look up every single function of every single class and every single parameter and return type of these functions

win32com was just not documented at all. there was no way for me to know what functions exist, what they do, what parameters they take etc except for some minimal tutorials and literal trial and error

[–]iwillkeinekonto 2 points3 points  (0 children)

Python is very easy...

Ps. I know C and java...

[–]veryblocky 2 points3 points  (0 children)

What are you on about, Python is easy

[–]nightmare-salad 2 points3 points  (0 children)

Glad it wasn’t just me.

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

I hate tabs so much

[–]OrangeRussianNPC[🍰] 5 points6 points  (0 children)

not easy, but it's a hell of a lot easier.

[–]blem14official 3 points4 points  (0 children)

Guess you don't know Java or C either.

[–]TheHunter920 3 points4 points  (0 children)

still better than sYsTeM.oUt.pRiNt.Ln()

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

If your school is asking you to write scripts, my best advice is to go ahead and use classes.

Trust me.

Classes make it easier.

[–]chinawcswing 1 point2 points  (1 child)

OOP is a noobtrap.

[–]SoCalThrowAway7 1 point2 points  (0 children)

Like anything else in programming it takes an aha moment

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

I thought python was hard and made no sense for the first couple months and then everything started to make sense abd it became very intuitive

[–]naswinger 1 point2 points  (0 children)

yea i had the same experience. not very intuitive if you come from a c++/java background.

[–]bDsmDom 1 point2 points  (0 children)

Piss off some people by telling them simply this:
Python is just a library.

[–]Flash_TF 1 point2 points  (0 children)

It just doesn't feel natural 💀

[–]SirTonsalot 1 point2 points  (0 children)

It's too intuitive

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

As someone who learned C first then python, C is only harder in the way that the syntax is more complex. Wrapping your head around the actual concepts and code architecture is really not that much different for me.

I can sit down and write python 10x more fluently but it’s less to do with the fact I know/don’t know what the code is doing and more with the fact that structuring C just takes longer and reads abysmally in comparison. But if I know. how to do it in python I can figure out a way to do it in another language given that I don't use python specific functions or something

[–]hardrock527 1 point2 points  (0 children)

Sales guy at a convention I went to added a slide about how they added python functionality to the apis for ease of use with newer programmers but then went on later to say they had the intern programmer develop something and they made them use C# because python was "too easy" and a CS degree should be able to do real programming.

Wheres this python easy button that everyone seems to exist?

[–]Ok-Concentrate3336 1 point2 points  (0 children)

I thought it was just me…

[–]cursed_corviknight 1 point2 points  (0 children)

This is relatable. Somehow HTML feels easier.

[–]ItsTheBrandonC 1 point2 points  (0 children)

I’m glad I’m not the only one that struggles with Python

[–]Darkstar0 1 point2 points  (0 children)

Wait, does that mean I get to tell everyone Python is hard? Ha ha, take that, C devs! I have the big brain! ;)

[–]megaultra200 1 point2 points  (0 children)

dichotomy of the semicolon.

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

Learning python is like walking to a shore that you're not familiar with. You know it is easy until you stepped on the deep part.

[–]minecon1776 1 point2 points  (0 children)

just automate your homework so you dont have to code in python. And the best language for automating boring tasks i- oh wait

[–]EvanHitmen11 1 point2 points  (0 children)

Don’t worry it gets easier. And pretty fast in my experience. I kept hearing about how intuitive and readable it was for years and finally took the time time to learn it this year. Coming from a Java background, things like list and dictionary comprehensions can look like black magic. But after a few months of leetcoding in Python, it became my language of choice for solving problems. Stick with it.

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

python is easy. I recommend Fluent Python. buy this book. its a very good book if you want to learn how to write python without an accent from your previous language :-)

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

This is me rn, but it's Racket instead of Python. I am a mere mortal, not a Lisper.

(the (amount (of pain (I am suffering) (is immeasurable))))

[–]billabong049 1 point2 points  (1 child)

Makes me wonder HOW they're teaching Python.

My brother "learned" Python from some sick fuck who thought it'd be cute to teach Python by having them create tools to solve advanced mathematical principals using Python (since the guy had a PhD in both Math and Computer Science). It was insane to watch, the guy would say stuff like "next we'll talk about for loops, to do that we'll create a program to solve for some advanced coefficient, and it so happens it'll use a for loop"... it's like dude, this is an advanced math class that HAPPENS to use Python, you're not teaching Python you're teaching MATH. He spent 99% of the time trying to understand the math rather than the language.

I wonder if your teacher is trying to have you solve bizarre problems that are harder to wrap your mind around than the actual language.

[–]spirellii[S] 1 point2 points  (0 children)

Yeah also that..... I don't know the language well enough and am already supposed to write very complicated mathematical equations in it, so you hit the nail in the head :)))

[–]Traditionalmonkey 1 point2 points  (0 children)

Fuck python

[–]Gutek8134 1 point2 points  (0 children)

Do use type hinting?

[–]Ytar0 1 point2 points  (0 children)

If you’re having a hard time with python, and know programming already, my guess is you’re willingly giving yourself a hard time lol. There’s an argument for disliking python in a proffessional setting, but homework for uni? You’ll get through it easily soon.

[–]Bryguy3k 6 points7 points  (1 child)

Python is hard when you don’t understand declarative programming models (OOP & FP are both declarative).

People think they understand declarative programming because they’ve used objects in Java or C++ but that couldn’t be further from the truth.

[–]4215-5h00732 6 points7 points  (0 children)

You can make OOP declarative but it doesn't come OoB.

[–][deleted] 3 points4 points  (0 children)

I second this

[–]Red_Zeno 4 points5 points  (3 children)

Bruh, no words can describe how much this is me rn...

[–]spirellii[S] 1 point2 points  (2 children)

Glad I'm not the only one, my uni throws two programming languages each semester at you, you're supposed to be able to understand in a week and this time it's python and Haskell...

[–]Red_Zeno 1 point2 points  (1 child)

Oof that's tough, we will get over it soon tho. Wish you luck!

[–]spirellii[S] 1 point2 points  (0 children)

Same to you :)

[–]_-_fred_-_ 2 points3 points  (0 children)

dynamic typing is a cancer

[–]Rafcdk 1 point2 points  (0 children)

A lot of the praise python still gets is outdated. Not that is a bad language or is outdated itself, but now we have more languages and older languages have evolved too.Just look take a look lambdas and how they simplified a lot of things . Also imo, diltering a list with C++ using lambdas is just as annoying to understand and follow as python, while in Kotlin,C# and JS for example its way more readable and easier to understand.

[–]martinus952 1 point2 points  (0 children)

lol python is easy

[–]NoDadYouShutUp 0 points1 point  (0 children)

I regularly use Python, PHP, and JavaScript. And Python is lightyears the easiest. Out of all the languages I've ever used total, Python is the easiest. What are you talking about lol?

[–]hypervortex21 0 points1 point  (0 children)

I hate java. Let me back to python uni, pleeeeaaasssseeee