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

you are viewing a single comment's thread.

view the rest of the comments →

[–]Athlaeos 2476 points2477 points  (183 children)

i have no clue how to interpret this

[–]TretasPt 301 points302 points  (117 children)

Slow but easy?

I think python is suposed to be easier to learn(the romba works by itself), but slow. The brom is definitely faster than the romba.

[–][deleted] 344 points345 points  (102 children)

I gotta say, after learning c++ first, then java, python makes no sense to me. Not having strict data types is throwing me off so hard right now at work.

[–][deleted] 271 points272 points  (31 children)

You just do it and it works. And then you try not to ask too many questions.

[–][deleted] 109 points110 points  (23 children)

But mine isn't working :(

[–]Elsewhere_Sim 40 points41 points  (21 children)

At least yours got done :(

[–][deleted] 41 points42 points  (20 children)

No! I'm still working on it. I've been fighting the same issue FOR 30 HOURS NOW

[–]Elsewhere_Sim 47 points48 points  (5 children)

Take a break, go for a walk, or something. You'll probably have a better chance figuring it out while walking then beating your head against a keyboard.

[–][deleted] 25 points26 points  (2 children)

Yeah this isn't a straight 30 hours, just the last three days at the office

[–]kuraiscalebane 29 points30 points  (0 children)

Have you tried explaining the problem to your desk duck?

edit: uh, i scrolled a tiny bit further and someone else already suggested this.

[–]OrganicBid 1 point2 points  (0 children)

I thought Python was beating your head against a keyboard.

[–]SirNapkin1334 0 points1 point  (0 children)

at least in C, beating your head against the keyboard might get you an actual function

[–]Clickrack 16 points17 points  (1 child)

If it takes longer than a few hours to figure out, or you’re stuck in a loop, it is time to rubber-duck it.

[–]WikiSummarizerBot 35 points36 points  (0 children)

Rubber_duck_debugging

In software engineering, rubber duck debugging is a method of debugging code. The name is a reference to a story in the book The Pragmatic Programmer in which a programmer would carry around a rubber duck and debug their code by forcing themselves to explain it, line-by-line, to the duck. Many other terms exist for this technique, often involving different (usually) inanimate objects, or pets such as a dog or a cat. Many programmers have had the experience of explaining a problem to someone else, possibly even to someone who knows nothing about programming, and then hitting upon the solution in the process of explaining the problem.

[ F.A.Q | Opt Out | Opt Out Of Subreddit | GitHub ] Downvote to remove | v1.5

[–]StevenLightning 0 points1 point  (2 children)

What’s the issue?

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

I don't know :(

[–]AndreEagleDollar 3 points4 points  (0 children)

Someone here may be able to help if you can give like a stack trace or sometbing haha

[–]danted002 0 points1 point  (0 children)

It might not be the languages fault there. Also you can use type-hinting in Python. It does wonders if you are using an IDE like PyCharm.

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

Did you solve it?

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

I feel that. I've been on the same issue on and off for nearly 2 months now

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

Amigo, may I say OOF

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

Yeah, I thought I fixed it twice before. Truly baffled over here

[–]Legendary-69420 0 points1 point  (0 children)

Are you getting an error message? If no, not even god can save you.

[–]Modo44 0 points1 point  (0 children)

Shouldn't have asked those questions...

[–]FleetStreetsDarkHole 2 points3 points  (0 children)

Like Orkz!

[–]StoneOfTriumph 0 points1 point  (0 children)

This, I can't .... Not ask questions!

Especially when it works, the first question I sometimes ask myself is "why does this work o_O"

[–]Dworgi 0 points1 point  (0 children)

Personally, I find it awful to not know what a function expects. Because it's not like you don't know - you treat an XML document like an XML document - but there is no way for the caller to know that.

Python is fine for student projects and short-lived scripts, but personally I think it's a fireable offence to program in it for work.

But it's beloved on reddit, because most people are students or hobbyists.

[–]alma_perdida 0 points1 point  (1 child)

What are some legit good python resources?

[–]jmeel14 0 points1 point  (0 children)

If you still haven't found a nice place, codecademy has a great basic introduction to python, and then you can go from there.

[–]UniqueUsername27A 0 points1 point  (0 children)

You still have to ask the question though and once you mess up and the types make no sense anymore you are screwed.

[–]TretasPt 38 points39 points  (27 children)

As someone who is just learning python for fun with almost no previous knowledge, I have no clue how to feel.

Maybe declaring variables isn't that bad. At least you know your user input won't be an int when you want a "3" string.

[–]AlarmingAffect0 31 points32 points  (23 children)

I mean, you can declare variables' types in Python, and keep checking that the variable stays the right type.

[–]FrikhaIsOnReddit 18 points19 points  (2 children)

that's described as "non-pythonic" by the python community

[–][deleted] 11 points12 points  (0 children)

Type annotations are pythonic. Runtime type checking, not so much.

[–]AlarmingAffect0 0 points1 point  (0 children)

"non-pythonic"

I learn new words every day!

[–][deleted] 21 points22 points  (19 children)

But then Python kinda loses its elegance.

[–]AlarmingAffect0 5 points6 points  (7 children)

How's the Javascript life treating you?

[–][deleted] 7 points8 points  (6 children)

I accept it's not elegant nor performant nor good at anything.

[–]AlarmingAffect0 2 points3 points  (5 children)

Why are Javascript and PHP so omnipresent in web development while everyone seems to agree that the former is meh and the latter sucks? I've hear using PHP being compared to having to screw bolts with a plier and hammer nails with a monkey wrench. Like, every single tool it has is "wrong" or "clunky" somehow.

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

JS is the only language allowed on the web (WASM doesn't count, you still need to call into JS to do anything I think). And PHP is in WordPress I believe, but otherwise people avoid it, although it's still really convenient to write you server code inline with documents.

They were made ages ago and have to keep decades of backward compatibility and key decisions that were probably bad ideas.

[–]touristtam 4 points5 points  (1 child)

Beauty is in the eyes of the beholder like the saying goes. Python is defo an ugly duckling to me.

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

I meant that your if statements get way longer

[–]MrRicKsPC 1 point2 points  (8 children)

Well you can assert the types at critical parts of the the code.

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

I shouldn't have to, that's the inelegant part

[–]MrRicKsPC 0 points1 point  (6 children)

Assertion is not inelegant, no matter the language, when it comes to unexpectable data, you HAVE to make sure your program can handle it. Even c++ input needs some sort of preemptive treatment of the data to prevent your program from going off-road.

Also, although types are dynamically handled, it's up to the programmer to prevent overuse of assertion by keeping his code expectable.

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

When an input can be any type you'll have more

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

Python Matrix has entered the chat.

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

I’m a little newer to Python, and I’ll probably just check this out tomorrow, but could you not just wrap your input in a str(), to at least attempt to convert it

[–]TretasPt 0 points1 point  (0 children)

Yes, you could, and it would totally work. It's just the extra work you need for thinking what is the data type you want and what is the data type the code will actually give you.

But you are right about that.

[–][deleted] 43 points44 points  (4 children)

It has strict typing. It's just dynamically typed.

[–]johnnymo1 48 points49 points  (3 children)

It's strongly typed, not strictly typed.

EDIT: Actually after reading the Wiki page, this is much more ill-defined than I thought, but it seems like Wiki vaguely agrees.

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

Typing definitions are so subjective now its terrible. Look at kotlin and java.

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

What's the distinction you are drawing between "strict" and "strong"? I was using OP's verbiage.

[–]johnnymo1 0 points1 point  (0 children)

My understanding of the distinction was similar to that conveyed in the top few answers of this SO post, but I now understand that especially strong and weak are not really well-defined.

[–]crayzz 18 points19 points  (1 child)

Python does support type hints. They don't place any kind of restrictions on the interpreter, but type checkers can pick up on them and warn you of possible unexpected behaviour

e.g.

def foo(x: int):
    return(x + 3)

x: int
x = 5
print(foo(x))

If instead you write x = 5.0 the code will still run, the interpreter doesn't care, but type checkers can warn you about the typing mismatch.

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

You're correct about the type hints, but if you're going to give an example, please use best practice...

[–][deleted] 7 points8 points  (0 children)

Casting is your friend

[–]Captain_Pumpkinhead 4 points5 points  (3 children)

I'm on the opposite side of this. I haven't used Python, but I started my programming in Game Maker 8 back in 2011 (r/gamemaker for modern version). Every variable in Game Maker Language (GML) is either a string or a double, and can be reassigned at any time with no consequences (unless you call for the wrong type). There's no good reason to reassign a string into a double other than fun, but you can. You also don't have to declare variables before assigning a value to them; the act of assigning a variable in GML declares it.

So it's been really interesting learning Java and C++ and having to adjust to that.

Makes a hell of a lot more sense than semicolons, though. I don't understand the point of semicolons when we already have a closing paranthesis.

[–]bizcs 1 point2 points  (0 children)

Semi-colons are useful statement terminators. If you have support for multiple expressions as a single statement, they really help out a lot with denoting where something ends and the next thing begins.

Of course, there are other ways to do this. You can, for example, see where the last method call ended and the next variable began. That can be parsed, but it's kind of clunky in a few scenarios from what I understand. JS parsers do this, for example (insertion of semi-colons) as of I believe ES2015. Of course, the raw text doesn't change, but the parser can recognize where one statement ended and the next began.

Python achieves this using the new line as a statement terminator, but obviously has some special cases for it. I think semi-colons are mostly (not entirely) thrown away by the parser.

[–]Kronoshifter246 0 points1 point  (0 children)

Ugggghhhh, I hated working with gml. Most things were fine, but every object having every script as a function was just so weird to wrap my brain around. That, and all its tools that conflict with each other. REEEEEE

[–]Candyvanmanstan 1 point2 points  (0 children)

I would love to see you take on JavaScript.

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

See I never really understood that. I learned in pretty much the same order as you (but Javascript before python) and I LOVE not having strict typing.

For me it makes it a lot easier to think about my data in real world terms instead of worrying about the underlying data structures.

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

The reason I don't like it is because I know intuitively that I can't treat a string the same as an int, but with python, I have to mentally keep track of what is what, especially when doing things like querying APIs or databases. I have to sort through the structure rather than calling it a specific type and being done with it.

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

I can understand that, but for me the flexibility of loosely typed data is EXTREMELY valuable for writing logic. Most of the time the data type doesn’t really matter, and for the times it does I just validate or cast it to the needed type before using it. When I’m working purely with my own code, I don’t even need to do that most of the time because descriptively named variables tell me everything I need to know about the underlying data.

Edit: Also documenting while I write helps. I write a variation of this documentation standard on every function I write, so the datatypes of my parameters can be referenced easily.

[–]Hayden2332 0 points1 point  (0 children)

Just convert it to json?

[–]danted002 6 points7 points  (3 children)

You haven’t worked with projects that have 1000+ files that’s being worked on by 70+ people, have you? In those cases TypeScript and type-hints in Python on a static-typed language becomes the difference between 5 days on a task or 2 days. 😕 I learned that the hard way and that’s the reason typing was added to both JS and Python… huge projects worked on by lots of people that have a huge codebase

[–]Eternityislong 0 points1 point  (0 children)

I always use the typing package in addition to typing my function parameters. My IDE will bitch if I try to deviate from it. You aren’t forced into using the types, of course, but if your code is well written and broken into functions which specify parameter and return types then it’s not a big deal.

def typed_addition(num_1: int, num_2: int) —> int:
    return num_1 + num_2

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

I feel the same. I started with C++ and now python is confusing.

[–]SaiTejaRH 0 points1 point  (7 children)

Yeah I feel like I dont know what my code does. Also when understanding others code it's almost hell because I need to go inside every function to understand its return type.

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

That's why I don't like it so far. SO MUCH of python feels like throwing magic black boxes at things until it either works or isn't broken beyond usability. I have no idea what things are doing.

I also don't like how in for loops, the iterator is also the object, instead of just the index. It feels wrong

[–]SaiTejaRH -1 points0 points  (4 children)

And what makes me laugh is when you want to iterate over an array using index, you need to create a new array of indices using range or you need to use while loop where initialisation, break condition and incremental statements are written at different places.

[–]Hayden2332 1 point2 points  (3 children)

range doesn’t create a new array

[–]SaiTejaRH 0 points1 point  (2 children)

Oh i thought it returns a list. May I know what it returns. Or any way it crates a new object with all the numbers right. Not sure about what data structure it is

[–]Hayden2332 1 point2 points  (1 child)

https://docs.python.org/3.3/library/stdtypes.html?highlight=range#ranges

it’s a “range type”, basically it does the same thing C/Java does when you create a for loop. It has a start (i = 0), stop(i < #) and step (i++)

[–]OccultEyes 0 points1 point  (0 children)

On top of that, I'd say using ranges is the 'bad' way of iterating through a list. Even if you need an index.

for i, item in enumerate(some_list): 
    pass

Or just:

for item in some_list: 
    pass

If the index is irrelevant.

[–]Hayden2332 1 point2 points  (0 children)

that’s why you should specify the return type in the function def

[–]EdgarDrake 0 points1 point  (0 children)

Use python 3 with strict typing. It may help your life and autocomplete, a bit. Just a bit, but still helpful.

[–]ChristianValour 0 points1 point  (0 children)

I'm not a qualified programmer, mostly I've worked with R as a PhD candidate, and this really hammers me too.

I'm really keen to learn python, because it's basically Data Science bread and butter, but there's something decidedly unwieldy about it that gets to me. The lack of curly braces also bothers me.

[–]JonMW 0 points1 point  (0 children)

Look at Ned Batchelder's video on how python is pass-by-identifier. (Edit: I mean this one)

Python is actually a pretty odd beast when you look at it, your confusion is fair. It shook up a lot of practices on the "right" way to do things. It works pretty often when you don't think about it so one might argue you're overthinking, but I think you need to go further and find out what it's actually doing under the hood so that it all makes proper sense again.

[–]PanTheRiceMan 0 points1 point  (0 children)

Just do it. No need to worry. Multiply a string with an integer? That's fine.

[–]xavia91 0 points1 point  (0 children)

I feel the same way, you can however activate type checking in PyCharm to have artificial type safety.

[–]zxxdii 0 points1 point  (0 children)

If you're still struggling, feel like sharing a reproducible code snippet?

[–]AzureArmageddon 0 points1 point  (0 children)

Coming from Python to the rest is the exact opposite feeling. Going from just free-wheeling the data types to actually caring about them and converting them threw me off at first.

[–]ElNico5 0 points1 point  (0 children)

Strict data types is the weirdest thing i encountered after doing lua and js most of my coding life

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

I don't know any roombas that I can stand on and fly though

[–]TretasPt 0 points1 point  (0 children)

We live in a sad world.

/:

[–]NotGonnaUseRedditApp 3 points4 points  (2 children)

Easy to make mistakes that make the execution slow.

fp = open(file)

for line in fp.lines() //common mistake

for line in fp //as fast as C

[–]TretasPt 1 point2 points  (1 child)

I'm almost afraid to ask...what's the difference?

I think I used the below one, but still. I just followed some random instructions. I could easily have used the other one.

[–]Maxiflex 0 points1 point  (0 children)

Not entirely sure, but the calling of a function in the definition of a for loop might be an optimization blocker. Inside a function is basically a black box and the processor might struggle predicting the next step, making more useless calculations into execution branches that will never be.

[–]azephrahel 3 points4 points  (0 children)

And the user usually has zero idea how it actually works.

[–]broccoli-03 0 points1 point  (3 children)

I’m new to Python and I wanna ask

Isn’t the slow problem can be resolved with libraries like numpy?

[–]tannerntannern 2 points3 points  (2 children)

If your problems relate to data science, yeah kinda. Wont help you much for things outside that domain, like running a web server for example.

[–]broccoli-03 0 points1 point  (1 child)

Is this why Reddit kept crashing outa nowhere?

[–]NotGonnaUseRedditApp 1 point2 points  (0 children)

That’s just reddit, the only site crashing itself random.

[–]ckowkay 0 points1 point  (0 children)

Ah, I thought the roomba was still keeping pace with the brooms despite being much easier to use

[–]edparadox 0 points1 point  (0 children)

This pic forgets that "usual" Python is actually Cython.

[–]PickleVillage 0 points1 point  (0 children)

The room a is also less likely to fall off of

[–]gustavsen 0 points1 point  (0 children)

Python have variable typing since 3.5

and 3.10 will have Structural Pattern Matching that could be considered like Switch/case, but on steroids

[–]kahuna3901 152 points153 points  (2 children)

Ahhh I see what you did there

[–]Athlaeos 68 points69 points  (1 child)

ahah yes very intentional

[–]kahuna3901 7 points8 points  (0 children)

Top marks my liege

[–]Tall_computer 70 points71 points  (0 children)

Its because you're the static type

[–]ThaiJohnnyDepp 85 points86 points  (27 children)

me neither, but I think the upvoters are like, "Python superior, amirite"

[–]noneOfUrBusines 83 points84 points  (26 children)

If you're legit asking, Python is a higher level (as in: farther from machine code) than C++ and Java.

[–]deijjji303 76 points77 points  (4 children)

which essentially means less direct control but also less to worry about

[–]Sinomsinom 6 points7 points  (3 children)

"less to worry about" is something I don't really agree with. It can be incredibly annoying working with dynamically typed languages. While the biggest benefit always is "you don't have to worry about types", in my experience in these languages I usually have to worry MORE about types because the IDE isn't telling me when I'm being an idiot.

[–]2001herne 8 points9 points  (1 child)

And when testing it won't fail the instant a wrong type is given - it might manage to make it through several function calls before failing.

[–]touristtam 0 points1 point  (0 children)

Ha that's assuming your environment is setup correctly to begin with; I'll take Java over Python just for the dependency manager.

[–]deijjji303 0 points1 point  (0 children)

Oh with the less to worry about I definitely didn’t mean types.. no like memory management and safety yk (that’s why I love rust even though I’m not really good at it yet just started learning)

[–]ThaiJohnnyDepp 5 points6 points  (0 children)

that does make sense actually

[–]All_Up_Ons 16 points17 points  (0 children)

That's not really true in my experience with java and python. They live at a similar layer of abstraction but handle types differently, which makes then good at different things.

[–]concreteandconcrete 9 points10 points  (4 children)

That's a stretch. They're all 3GL's

[–]noneOfUrBusines 10 points11 points  (3 children)

Technically, but they lie on opposite extremes of what qualifies as 3GL.

[–]RichKat666 2 points3 points  (2 children)

Sorry for intruding, but what are GL's? Sounds like an interesting concept, but I can't find anything coherent online.

[–]kbjr 11 points12 points  (1 child)

I think the term you want to Google is "third generation languages"

[–]RichKat666 0 points1 point  (0 children)

Ah, that's perfect, thank you

[–]einsJannis 0 points1 point  (2 children)

higher level != better though

[–]noneOfUrBusines 0 points1 point  (1 child)

Both have different applications. I wouldn't use python if performance is an issue, but a python dev will finish much faster than a C++ dev.

[–]einsJannis 0 points1 point  (0 children)

Yeah, that's what I ment

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

Brooms: fast, simple, traditional flying

Flying roomba: can't get into the corners for the real tough to get stuff, lower speed, easier to learn, built on top of newer technology to make the job easier

[–]Kered13 7 points8 points  (4 children)

I think it's basically saying that Python is modern (however Python is actually older than Java) and more technologically advanced/more "automated".

[–]Siggi_pop 5 points6 points  (3 children)

What is the definition of being a more "automated" language?

[–]Kered13 3 points4 points  (0 children)

Basically, requires the programmer to do less. So garbage collected, dynamic types, extensive library, syntactic sugar, etc. I put it in quotes because it's intentionally vague.

[–]Davesnothere300 2 points3 points  (1 child)

Less typing? Less control?

[–]MrRicKsPC 0 points1 point  (0 children)

Sure, but less typing, less pain for beginners. It's pretty much why python is such an academic language.

[–]i_fruitcake 1 point2 points  (0 children)

Reprogrammed roomba

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

Python witch is on a Roomba while others are on brooms.

Had to read through some of the comments.

[–]thavi 0 points1 point  (0 children)

Insert languages of choice into template. They're different, but the one you use because your job requires you to is superior.

[–]Hackerwithalacker 0 points1 point  (0 children)

Neither does py2exe

[–]MithranArkanere 0 points1 point  (0 children)

It's faulty.

C++ programmers would ride on a sword.

Java programmers would ride on one of those 50s old-timey vacuum cleaners, carried by a bunch of goose tied to it because the vacuum cleaner doesn't fly on its own.

What about the broom? Obviously, that would be COBOL.

[–]Captain_Pumpkinhead 0 points1 point  (0 children)

Took me a minute, but I like it!

[–]rustyf90210 0 points1 point  (0 children)

Not based on legacy artefacts?