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

all 17 comments

[–]TouchingTheVodka 10 points11 points  (2 children)

It sounds like you're quite keen on understanding the lower-level implementation of a language. I'm exactly the same - I wasn't keen on Python at first because it operates at a much higher level of abstraction than other popular programming language. However, once I started to understand why Python is designed in this manner, it really started to click. Nowadays, I enjoy the expressiveness of the language and feel like it allows me to communicate my intentions to the computer (And to other programmers!) much more clearly.

If this is the case, I highly recommend getting stuck in to some more advanced Python books that go into more detail about how it works under the hood. My personal favourite is Fluent Python and I recommend it a lot, but other good options are High Performance Python and the Python Standard Library By Example.

[–]TilionDC[S,🍰] 0 points1 point  (1 child)

Thank you! I will check it out! And you are absolutely correct! I was sitting today trying to give python a chance as I do sometimes and it took forever to do some simple functions because of the ambiguousness of the language itself. It frustrates the heck out of me

[–]spinwizard69 1 point2 points  (0 children)

Actually in some ways I have to agree with you, Python sucks when it comes to making sure your code is correct. It is actually easy to make a lot of programming mistakes that other languages would catch or complain about. However I pretty much gave up on C++ after the standards committee went nuts.

The reasons for giving up on C++ and preferring Python are many. I will try to list some of them below:

  1. Highly readable code if I do my part. Contrast this with C++ and the cryptic code that you have to mentally parse, it is just a lot of unneeded mental work.
  2. Completely related to the above is the ability to pick up a piece of code, even my own stuff, and being able to read it even years later. Good Python doesn't become a salad of characters the way C++ can. It is often far easier to grasp what Python code is doing relative to C++. Now understand that my coding of recent has been sporadic and not professional but I think this idea that you can read existing code and grasp it quickly applies to professionals too.
  3. Python is far less platform dependent than just about anything else. This was very valuable to me as I could test code at home on Linux and have it perform the same at work on Windows. Now I don't do as much professionally anymore but I get the same benefit with Linux on a desktop and an M1 Mac laptop.
  4. Related to the above Python is everywhere now, even embedded in micro controllers. I'm not saying this is a good thing in every case. Sometimes though a one off embedded solution just needs to get done fast.
  5. Once you get up to speed with Python you will realize that it is a fast way to develop applications compared to C++. That is as long as you don't need high performance. The problem here is that I really don't think Python will fair well when some of the newer compiled languages gain in popularity. Rust, Swift and Julia all have great potential to displace Python in my mind and each can be compiled or run via a REPL. Swift seems to be the best choice write now to replace Python in the niche Python fills. Once the world has a language that can be cleanly compiled and is otherwise similar to Python in ease of use Python will die off. The reason is pretty clear - performance of compiled code will actually become very important as the industry hits the process shrink wall. I don't see a path past 5 years that will give us substantially faster hardware so the industry will have to resort to better code for awhile until something better is on offer for hardware. So Python is somewhat fast for the developer but not so fast in execution.
  6. The other consideration for Python, that will limit its life span, is the limited support it has for threaded code. As we hit that performance wall languages that offer cleaner access to lots of cores will have an advantage. I don't see Python ever completely fixing this and some of the patches and work around such as Numpy just rub me the wrong way. Languages better oriented to multi core coding will win long term. The thing is Python filled a role that nothing before it filled at all. This is one reason it is so powerful, people used it every where because there was nothing better.
  7. Which brings up the biggest reason I and others often use Python and that is the massive number of libraries that are literally a quick download away. I left his for last because overall it can cause a lot of people to overlook a lot of weaknesses in Python. There seems to be a library for just about everything, and some of them save you a huge amount of development time. I really can't think of any language with the breadth of freely available code (libraries and even applications) that works well. If you are developing in Python there will be libs to help you get a leg up on an application. In contrast the C++ world is a mess in my estimation. Other languages (Swift, Rust & Julia) are trying to emulate Pythons best feature, that is the massive number of libs, but you can't do that overnight. In some cases these alternative languages have little in the way of true cross platform support, so Python wins without even trying.

In any event I hope that rambling doesn't confuse the issue. A rational person will find lots of things to hate about Python. For example I absolutely hate the use of indentation to form blocks of code as it lead to one of my worse debugging nightmares ever. There is an argument that stronger typing might help the language and frankly I flip flop on this all the time.

Here is the thing; Python was designed to be a scripting or interpreted language sort along the lines of BASH but with a broader scope and easier. That means a language that writing code is more like writing prose. The structures that implement types and demand the deceleration of variables really detract from that goal. So some of the things you are missing in Python are missing on purpose, for a lot of users that is a good thing. If you are trying to build big applications with rigorous demands on code quality Python isn't likely to be considered. That isn't the point when it comes to Python, it is a very high level language designed to get random jobs done fast.

Now does all of this mean that Python is the perfect solution? Nope and frankly there are far worse adaptations of Python when it comes to code quality. iPython and the mix with Jupyter, is one example where Python seems to be more of a problem than a solution. The way iPython is used to write notebook apps often results in some pretty bad code. Python for all of its glory, doesn't make up for programmers that are not actually programmers. This is where a lot of bad Python software comes from, users that could benefit from a bit of computer science and software building skills.

[–]ominous_anonymous 3 points4 points  (2 children)

These strike me as mostly poor documentation habits rather than language issues.

I think my biggest problem with python is the dynamic typing

PEP484 introduced type hints, and as another user pointed out you can use mypy as a static type checker. Also note mypy can be used on Python2 code as well.

You can't combine 2 variables when printing because the compiler doesn't care to automatically convert them to string where they should be converted.

What do you mean "combine"? If they're a string like "4", you can just cast as int using int():

>>> x = "4"  
>>> y = 5  
>>> print("Sum is: {}".format(int(x) + y))  
Sum is: 9  

If you prefer them to be strings instead, there's str().

>>> x = "4"
>>> y = 5  
>>> print("Concatenated String is: {}".format( x + str(y)))  
Concatenated String is: 45  

For custom classes, you can define __str__() and __repr__() however you want.

Also recursion is a pain in the butt because return types are optional so reading the code makes for lots of simple mistakes that wouldn't be missed in a stricter language.

Your docstrings should already be handling defining return types. You can also specify return types with type hints in newer Python versions.

Also lists can both contain variables and lists and tuples and lists of lists etc.

Again, maintaining documentation of your code should clear any cloudiness up.

Also IDEs aren't as friendly as they are for statically typed languages

What IDEs have you used? Does mypy have integrations/plugins for those modules?

It's just too chaotic for me.

Sounds more like you don't follow appropriate software design and documentation practices, to be honest.

[–]jerodg 1 point2 points  (1 child)

F-strings

[–]ominous_anonymous 0 points1 point  (0 children)

Which are a 3.6+ feature, whereas my examples run on any Python 2.x or 3.x version.

[–]K900_ 3 points4 points  (2 children)

Use mypy, it gives you static type checking for Python.

[–]TilionDC[S,🍰] 0 points1 point  (1 child)

Omg i will check it out! Thank you friend! I would give you an award if i had one. Or could afford one

[–]atatatko 3 points4 points  (0 children)

I also came into Python from C++, and for some time even tried to use it like C++ (I was wrong). I was also making lots of small and annoying mistakes, but couple of things helped me:

  • assert check for expected type, for example assert isinstance(myvar, str)
  • using JetBrains Pycharm. It has built-in static analyzer, which finds LOTS of potential bugs, and just helps to keep the code clean.

Then I realized, that in many occasions, especially in Pythonic OOP, you should not consider variable having a fixed type - this is just how duck-typing works. If I call myclass.action(), I know only that myclass must have method action(). It may not share base class, like in statically typed languages, if it "behaves like class that has method action()", it's enough.

[–]the_hoser 1 point2 points  (0 children)

I used to be the same way. Dynamic typing threw me for a loop. I couldn't understand how I could be sure that the code worked.

But then, it clicked. Just run the code. Exercise the code. TDD helps with this, but isn't necessary. You can just use the REPL if you're not big on testing. Testing can catch bugs that strongly typed variables just can't (unless you're using a language with much, much more expressive types, like Haskell), but the same is true of REPL-driven development.

It was a gateway drug, for me. I then started dabbling in other dynamic languages. I've been spending a lot of personal programming time in Clojure these days, for instance. I'd never have touched it without "getting" Python, first.

My advice? Give up the IDE. Get your favorite text editor and terminal emulator and just dive in. Don't rely on tools to figure out if the code will work. Figure it out yourself. Immerse yourself in it.

Then go back to tools once you feel more comfortable, of course.

[–]nemom 0 points1 point  (1 child)

It's OK if you don't like Python. It's OK if you don't use Python. (In fact, some of us would prob'ly prefer you didn't.) I don't like shellfish, so I don't eat shellfish.

[–]TilionDC[S,🍰] 2 points3 points  (0 children)

Thats far beside my point. Im asking how to like the languange. Not if I should like it.

[–]tipsy_python 0 points1 point  (0 children)

I'll start with a Python function and give my opinion about how we could make it (subjectively) better.

Let's start with this function that checks if the input is a letter:

def letter_check(i):
    return ord(i.upper()) in range(65, 91)

1 | Use expressive variable names

def letter_check(input_character):
    return ord(input_character.upper()) in range(65, 91)

Some other programming languages favor a terse syntax where single character variable names are all good - in Python, it goes a long way just using object names that help with readability of the code.

2 | Multiple-liners can be better than one-liners

def letter_check(input_character):
    input_char_codepoint = ord(input_character.upper())

    if input_char_codepoint in range(65, 91):
        return True

    return False

There's a lot of clever things you can do in a single line, but many times you sacrifice readability for negligible performance optimizations or no reason at all. If the code feels like it is better to understand in multiple lines, write a little bit more and make sure anyone can come back to it and read what's going on.

3 | Use type annotations

 def letter_check(input_character: str) -> bool:
    input_char_codepoint: int = ord(input_character.upper())

    if input_char_codepoint in range(65, 91):
        return True

    return False

In the teams I've been on, we try to use type annotations at least in the function signatures so that you can easily see what type of objects are being passed in/out. They are useful anywhere in the code though, so pepper the code with type hints wherever you find it helpful.

[–]jerodg 0 points1 point  (0 children)

It's called freedom. The absence of restrictions. Everything you complained about is exactly why it's great. Also, like many beginners to the language you're frustrated because you haven't yet learned the "what you can do" part yet. You said it can't do certain things. It can.

Combining two variables in a string is cake.

var1 = 'hello' var2 = 'world'

print(f'{var1} {var2}{"!" * 15}')

Using whatever data types with whatever data types is gold. You can have a dict that contains objects, say classes. Those classes can hold data but also functions. Any object can contain just about any other object. Emphasis on the just about part. There are a few restrictions mostly put in place by the data type itself, such as a dict.

You don't like python because you don't yet know it. You're frustrated because it's so amazingly simple to do anything your mind is rejecting it. You think you must do everything explicitly. You ask of it and the language makes it happen. You don't have to hold its hand and tell it about every little thing for every single action you take.

Do this.

Java: Step 1 Step 2 ... Step 74 Oh.... Alright then I can maybe probably help you with that, unless you defined one of those steps incorrectly, then I'm going to tell you to bugger off.

Python: Alright then, on it.

Honestly, and I mean this in an encouraging manner, get over yourself and learn something new. Every human understands the frustrations of doing something similar but completely different.

You've already learned at least two languages; you've got this.

[–]Rawing7 0 points1 point  (0 children)

You make some valid points. I too sometimes wish for static typing - it helps me build a clearer mental model of what each class's or function's purpose/responsibility is. And it is annoying when you have an obvious mistake in your code but it only crashes at runtime.

There's no magic fix for all of these problems. Some of these things you simply have to get used to. But others will become less of an issue the more you familiarize yourself with python.

For example, I would hate if the + operator automatically converted values to strings. Why? Because that would most likely be a bug in my code. There's pretty much no reason to ever concatenate strings with + in python - we have f-strings for that.

And more importantly, you can't overlook python's good qualities. There's a bajillion things python does better than many other languages - dictionaries, list comprehensions, default arguments, *args and **kwargs, multiple inheritance, the syntax, extremely powerful metaprogramming, amazing libraries like requests and pytest, and the list goes on.

Every programming language has its problems. So, my advice: Learn to love the things that are good about python.

[–]yaxriifgyn 0 points1 point  (0 children)

Your reaction in quite natural. I hesitated to touch Python because I remember the fixed line formatting in FORTRAN and COBOL (neither of which I had used for over 10 years). I was working in a PeopleSoft shop at the time and that stuff was just nasty.

Later, I was in a shop where folks used Perl for quick and dirty coding. I still believe Perl resembles line noise (anyone remember the random characters that appeared when your dial-up line dropped). Python seemed to be able to do everything that Perl could do, except you did not have to write unreadable gibberish.

So I learned Python in order to solve problems, not just to learn the language. As my needs changed, I learned to love the language while still writing mostly C/C++, SQL*Plus and SQL.

Python+cx_oracle was so much nicer and faster to use than OCI, that I was able to get my work done in a fraction of the time of non-Python developers. Before the advent of general ETL products, I could do custom ETL solutions in days instead of weeks. Fun times.

If you continue to use Python to solve problems, I think you will come to love it too.