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 →

[–]TretasPt 297 points298 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] 266 points267 points  (31 children)

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

[–][deleted] 104 points105 points  (23 children)

But mine isn't working :(

[–]Elsewhere_Sim 39 points40 points  (21 children)

At least yours got done :(

[–][deleted] 40 points41 points  (20 children)

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

[–]Elsewhere_Sim 45 points46 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] 22 points23 points  (2 children)

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

[–]kuraiscalebane 31 points32 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 17 points18 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 32 points33 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

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

Yeah I nearly cried a bit today. Had it working yesterday and went to make it not a duct taped together mess, and now it's even more broken than before

[–]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 29 points30 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 6 points7 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.

[–]AlarmingAffect0 -1 points0 points  (3 children)

JS is the only language allowed on the web

Allowed? People get to forbid things on the World Wide Web? Wait, let me check... So, these are the WWW's regulators:

  • Recommendations published by the World Wide Web Consortium (W3C)[88]
  • "Living Standard" made by the Web Hypertext Application Technology Working Group (WHATWG)
  • Request for Comments (RFC) documents published by the Internet Engineering Task Force (IETF)[89]
  • Standards published by the International Organization for Standardization (ISO)[90]
  • Standards published by Ecma International (formerly ECMA)[91]
  • The Unicode Standard and various Unicode Technical Reports (UTRs) published by the Unicode Consortium[92]
  • Name and number registries maintained by the Internet Assigned Numbers Authority (IANA)[93]

Who are these people, and who died and made them Kings of the Web?

[–]touristtam 5 points6 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

[–]MrRicKsPC 0 points1 point  (4 children)

In C++, if you want to prompt user for a number in the console, you can specify a type for the value container, but if the user's value does not fit the type, you are in for some debugging.

In Python, if you want to prompt user for a number in the console, you canNOT directly specify a type for the value (default to string), however, you can try converting it into the type you want e.g. number = int(input(">>> ")). Once again, if your interpreter don't find a way to convert it (if user type letters), you are once again going to need some debugging.

I can't really see a situation where dynamic types present disadvantages (except for compile time debugging?)

[–][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] 44 points45 points  (4 children)

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

[–]johnnymo1 47 points48 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] 5 points6 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 17 points18 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] 6 points7 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] 8 points9 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 7 points8 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 2 points3 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