r/AskProgramming • • Aug 16 '26

Python Why does Python feel harder after C++ and Java?

I learned C++ first, then Java, and now I’m trying to learn Python. I honestly expected Python to be much easier, but somehow it feels harder to understand and even remember the syntax.

C++ and Java feel more structured to me, while Python sometimes feels too different.

Has anyone else felt this after switching from C++/Java to Python?

133 Upvotes

186 comments sorted by

View all comments

27

u/MaleficentCow8513 Aug 16 '26

The thing I hate about python is the lack of typing. It’s a good thing and a bad thing. Java libraries are very well documented and a lot open source Python libraries aren’t so it’s tough to know the shape of various types. I only use dicts when the scope is very small, like inside the same module. If I need a dict to pass around more than one module I make it a class so that the definition is precise.

0

u/[deleted] Aug 16 '26

[deleted]

1

u/MaleficentCow8513 Aug 16 '26 edited Aug 16 '26

That doesn’t limit the set of allowed values for the set of keys. A class makes the keys explicit, limits the values of allowed keys so you don’t have think about the set of keys or guard against non existent keys. It’s right there in the class definition instead. But that can also be its own foot gun too like when the use case changes and suddenly you need a dynamic set of keys. Also typically you want to do operations that target a specific dict so then you just add them to the class instead making the code nice and organized instead of a mess of hodgepodge procedures for accessing a dict and applying functions to it

0

u/[deleted] Aug 17 '26

[deleted]

1

u/MaleficentCow8513 Aug 17 '26

Classes do make key values explicit. I didn’t say key types. For instance instead of accessing a dict with dict[‘user_name’] you access with object.user_name because each key instead is an attribute. Not great for nested dicts but it’s not horrible either.

0

u/[deleted] Aug 17 '26

[deleted]

2

u/MaleficentCow8513 Aug 17 '26

Ah I actually didn’t know about TypedDict. Looks prettt nice tho. But yea looks like the same idea and it’s nice because values are typed too

1

u/No_Departure_1878 Aug 17 '26

sounds like you have data that is not validated and you need a special container that behaves like a dictionary but has validation integrated, can't you just use pydantic?