r/Python • • Jan 05 '18

Really??

Post image
2.0k Upvotes

317 comments sorted by

View all comments

83

u/Pancakepalpatine Jan 05 '18

I actually did this exact same thing.

I started with Python, but couldn't wrap my head around what it was actually doing for many of the code snippets and examples I was looking through while I was learning. On top of that, there were 23 ways to write the same expression with 16 standard library choices you could use. After a month or so of frustration, I quit programming for about a year.

Then, I tried to learn Java. The amazing thing was, there was little magical syntactical sugar (compared to Python), and so I could actually read and comprehend code. The JVM was confusing, but as an introductory language, having conventional long variable names and descriptive methods was really helpful.

I know this isn't everyone's experience, and in fact it's the opposite of many people's, but Python was way too "wishy-washy" when I was starting. Now, though, I love it.

(P.S. this was my experience based on the way I learn things, and your results may [have] differ[ed].)

(P.P.S. I learned to code back in the day with codingbat.com. If you're just getting started, it has the most basic of the basic, no-frills tutorials. Even CodeCademy or similar has a bunch of extra stuff, that may be helpful, or may not.)

6

u/anvils-reloaded Jan 05 '18

Every time I've asked about how to pre-allocate some space in a dictionary where I know the exact keys I want to have, I've always gotten the answer of "don't worry about it" or "stop trying to prematurely optimize your code". In any other programming language, this would just be a part of the process of writing the code. I really do want to learn Python better (I've done some work on Python projects without really knowing what I'm doing, just winging it), but it's not something that I can just stop caring about.

3

u/Smallpaul Jan 05 '18

If you want to preallocate with known keys then a dictionary is probably not the right data structure. You could use a class with _ _ slots _ _ or a struct.

But usually the people telling you not to prematurely optimize are right. You didn’t really explain why you feel this is bad advice.

1

u/anvils-reloaded Jan 05 '18

If I know what the keys are, I don't really want to load them one at a time, right? This is for situations where I have a specific sized table that I want to use for counting. (I was originally going to use a list but decided that they're not really designed for lookup like dictionaries are). I don't consider it premature optimization because I'm not really optimizing anything, just applying what I know about the problem.

3

u/z0mbietime Jan 06 '18

example = {x: None for x in y}

But based on what you’re describing a collection makes more sense. That being said they’re all right that this is sweating the small stuff. For one, using Python and getting the count when querying the database is going to be faster than anything Java can do.

1

u/Smallpaul Jan 06 '18

I think it's confusing to bring a database into the conversation. Did he say that the data comes from a database?

1

u/z0mbietime Jan 06 '18

I saw table and was running on almost no sleep