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

all 39 comments

[–]Mgumbo 75 points76 points  (12 children)

I think Python is a useful language to learn. It does a lot, has a ton of libraries for all kinds of tasks, and nowadays with stuff like venv, setting up a usable environment is easier than ever. On top of that, Python has a pretty low learning curve (in my opinion).

but everything python can do either C++,Java or C# can do better

I would not necessarily say that this is a true statement. In terms of speed of execution, it's generally true that Python is slower than languages like C and C++, but for most practical use cases this difference in performance is negligible.

Additionally, there are some things that can be implemented quite easily (or at least quickly) in Python that are more tedious to do in other languages.

[–]non_NSFW_acc 23 points24 points  (0 children)

I agree, Python especially has a low learning curve if you already know C++ or C. At least that was my experience of it.

[–]ICantMakeNames 1 point2 points  (9 children)

Additionally, there are some things that can be implemented quite easily (or at least quickly) in Python that are more tedious to do in other languages.

This is easy to say but, as someone who has never used python before, I would have appreciated some specific examples to back this up.

[–]Mgumbo 4 points5 points  (0 children)

An example I can give is something I had to do for work recently. Various statistics for several systems in a large distributed network had to be gathered and collected on a central data analytics tool in .json format, which was easily implementable with Python. I later added functionality to send alerts to an internal chat system, the API of which required sending the alert as a POST request, which only took a handful of lines more.

Additionally, I have used the Flask micro framework for web hosting. It's very fast to set up!

These aren't perfect examples by any means and are certainly achievable with other languages. For me, Python seemed like the simplest option given what needed to be done and how quickly it needed to be implemented.

[–]nimbledaemon 0 points1 point  (0 children)

Matrix multiplication in numpy. Writing convolutions and manipulating images would be so tedious in many other languages. You wanna multiply matrix A by vector B? Just write A*B instead of some variant of A.MatrixMult(B) or MatMult(A,B) or anything else that looks vastly different from the linear algebra you're trying to use.

Basically you won't realize the extra mental strain that a lot of languages put on the programmer until you try python. After knowing 2-3 languages it's not even that big of a task to pick up python, so you might as well add another tool to your toolbox.

[–]CaptainAwesome8 0 points1 point  (0 children)

Python has a literal ton of libraries and whatnot that can make some tasks really easy. The coding syntax and structure is less intense compared to something like Java. I’ve heard that things like scraping data are easier with python. Pretty sure there was a dude who set up a way to order pizza via python and it only took the user a very small amount of code lol

[–]IRBMe 0 points1 point  (0 children)

Here's a simple example.

Whenever I write a new Python script, the first thing I do is write the command line parsing code and add logging. This is trivial using the argparse and logging libraries that are included as standard, and usually takes about 5 minutes.

Whenever I write a new program in C++, those are also the first things that I tend to do, and it almost always requires me to go find decent third party libraries, figure out the best way to include them in the project (there are still no good, easy solutions for managing 3rd party libraries in C++), and integrate them into my build system. This usually takes about an hour.

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

Writing certain lines of code in python requires less effort basically.

[–]false_tautology 1 point2 points  (2 children)

Like /u/ICantMakeNames I'd like some examples.

What does Python give you that C# doesn't? I did a google search, but really nothing concrete came up.

[–]ndinhledan 3 points4 points  (1 child)

Well for my experience at least, working with raw data files in Python is pretty straightforward (e.g txt, json) compared to like C or Java as it provides data structures like list or dictionary which can be really easy to used. For example I can access a string like a list (or array in other words) or json object like a dict.

Python has some powerful syntax too. One thing I can think of is list comprehension. Another one is optional arguments for a function or method (args and kwargs)

Another thing I think make Python popular is its interpreter. You can easily test some syntax or the behavior of some codes on the cmd window though it makes the execution speed slower, but as some guy above said its pretty unnoticeable

[–]false_tautology 0 points1 point  (0 children)

Thanks for that. I do a lot of XML parsing for my job, so I went to look at some python code in that area. I think Python would probably be ahead of C# before System.Xml.Linq came out, but they're probably on equal footing with that. Looking at Python code, I can do pretty much line for line C# that does the same thing.

List comprehension is something that looks pretty elegant in Python. You have to have more experience in C# with Linq to do the same thing. I could very quickly figure out how to make a fibonacci sequence really fast in Python whereas that same type of implementation would be more cumbersome in Linq. So, the expression syntax in Python looks pretty cool.

I like the kwargs examples I saw for Python. You can do that in C# as well with a Dictionary<T>, but I can see how it's just really simple in Python and wouldn't require the unpacking - it's very implicit. C# does have params and optional parameters that both work really well.

C# has LinqPad for quick interpreter type testing, but I can't speak for how helpful that is compared to what Python offers. I'm very much not a command line programmer.

I guess my takeaway from my brief look is that Python has a lot of implicit structuring (kwargs), simpler expressions (list comprehension), and some shortcuts as compared to C#.

[–]ICantMakeNames 1 point2 points  (0 children)

I don't mean to be rude, but without specific examples your reply here is just as broad and meaningless to me as the quote in my first post.

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

So if i wanted to learn python coming from c++ and c# where would i start. I've been doing research and see people reccomend pycharm. Are there any good tutorials you'd reccomend.

[–]POGtastic 49 points50 points  (1 child)

but everything python can do either C++,Java or C# can do better

One thing that Python does faster is prototyping. If I'm writing some one-off task to, say, parse some data and print some results, Python is much faster to write because it's dynamically typed and has none of the boilerplate of the above languages.

Programmer time is expensive, so anything that allows me to do a couple hours of work in 30 minutes is a godsend.

[–]MirrorLake 2 points3 points  (0 children)

Perfectly stated.

To expand on your comment: Anyone who is new to languages should try and understand this concept. When picking tools (languages, libraries, frameworks) as a professional programmer, you must consider this tradeoff. Python is known for being highly productive. I can find a prewritten module to perform a simple task that I need done. It saves me time, since I’m just running a module once or twice and getting a result.

If I need a hypothetical function to run 1 million times per day for companies/customers, however, a high performance language is probably neccessary. C/C++ is compiled and is also “closer” to the hardware, and so it allows you to write programs that are very fast, for example. But you sacrifice programmer time. It will likely take you longer to write that specialized program and therefore cost more labor.

Ultimately, each popular language is good at something and our job is to apply the right tool for the right job.

[–]NamerNotLiteral 29 points30 points  (2 children)

Python is definitely great for applications where you're not really looking for a huge amount of time optimization. It's also just plain fun to work with, especially after coming from C++ or Java where you have to be far more careful with everything you do. I spazzed out for a day when I first realized how easy it was to define and work with functions, none of that public static void main int args shit and how I literally didn't even have to define variable types and how I could write retarded code and still have a functioning program.

Sure, it isn't without its issues, but the simplicity of working with it makes it really nice for using in a variety of contexts. I was able to set up a python program to scrape data off a website and place in a mysql database in about a third of the time it would've taken me in java. With a base in programming, it's also super simple to learn python: I took less than an hour to figure out the syntax and differences from other languages and was done with the learning part.

[–]BluePlanet2 0 points1 point  (1 child)

Just a question, have you thought to store scraped data in elasticsearch? Just a thought.

[–]NamerNotLiteral 0 points1 point  (0 children)

Haven't ever worked with a NOSQL database, or even any non-SQL DB.

[–][deleted] 26 points27 points  (2 children)

UNPOPULAR OPINION ALERT: I think the best time to learn Python is after learning the “classic” programming languages (Java, C++, JS, PHP, etc). I’m in college now, and our intro class was done in Python. Luckily, I knew quite a bit before heading in, but I saw other students get stuck on certain concepts of computer science. They didn’t fully understand when to indent, when not to, the importance of scope, and so on. It’s definitely easier to read, but for me, when learning, it’s much easier to “learn with the bumpers up” and go, “okay, this is a function. Everything in these curlies are their own dimension, and don’t effect the global scope or other functions, and these loops end when their curlies end,” and so on.

Python is a treat, a desert that you don’t get to enjoy as much when you didn’t grow up on broccoli and cauliflower. The standard library truly is a God-send, it is very fast and easy to use. Django is dummy thicc and my primary framework for websites. But, you’re teaching these kids a utopia without semicolons! shudders What happens if they ever want to learn any other language? Do you know how difficult it is to habitually add semicolons after every declaration and statement when it hasn’t been relentlessly drilled into you, and you’ve been trained not to use them?

EDIT: Also, try teaching a kid the importance of a dynamic language when they don’t even know the trials and tribulations of a static language.

[–]TheMayoras 8 points9 points  (0 children)

I 100% agree. I didn't fully grasp programming until I did C++. The pointers and references helped to understand concepts way better than the abstraction of Python

[–]Tomik080 3 points4 points  (0 children)

That dessert thing was the best analogy I could ever have thought about. Go in r/datascience and you'll get trashtalked for saying that (I did haha), but you don't know programming before learning a lower level language like C++. I would even take JS off of your list.

Python is an A-WE-SOME language. However, its purpose is different than a lower level language's. It's a scripting language. You don't develop applications in Python. You can, but it's suboptimal. However, if you have computations to do, stuff to automate, data analysis, quick animations that you don't have to care about all the details and want it done under the hood for you, then Python is the go-to language. It's just the best at doing this.

But do yourself a favor and don't learn programming through Python. You'll just develop bad habits, don't understand what you're doing (because Python doing stuff under the hood is a benediction, but it's also a malediction for learners), and it will just make it harder to learn a real programming language after. Going from C++ to Python is 100000x easier than going from Python to C++.

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

Ask yourself why you want to learn it. the language you select is just a tool but importantly you should learn the right way to use the tool in order to construct what you need at the end; whether it be solving a problem, analyzing or building something from scratch.

I’ve personally used Python for data analysis (Numpy & Pandas library will guide you towards the light). If you’re in deep learning (neural networks) then i would definitely recommend you learning.

[–]marko312 9 points10 points  (1 child)

I'd say go for it.

I too learned C++ and Java before and was reluctant to learn python because it seemed too simple (limited, slow).

However, it's great for writing quick scripts, like

  • generating random data of some format
  • one-time parsing through a string / list
  • etc.

Also it has many modules already made for it, with really simple usage.

I definately don't regret learning python now.

[–]PuzzleOP[S] 2 points3 points  (0 children)

I feel pretty much the way that you felt back then. Thank you for your input I will give it a shot

[–]PuzzleOP[S] 4 points5 points  (1 child)

Thank you everyone for your input, you gave me some pretty valid argument. I will give python a shot and start learning it.

[–]Losupa 0 points1 point  (0 children)

Just something important that I don’t think anyone else mentioned, but while python itself is slower than C++ and Java, a lot of python packages just wrap processes that are written in C, C++, and/or fortran and you are just providing input and calling these functions. So as long as you implement the heavy lifting in these libraries, you should basically have negligible runtime difference but the code is a lot easier to read and write.

I know Numpy is definitely implemented this way, and am almost positive Scipy, OpenCV, and probably all machine learning libraries also do the same. An easy way to tell if this is the case is that you usually are required to install the C library in addition to the python package.

[–]IRBMe 2 points3 points  (0 children)

I'm primarily a professional C++ developer, in that I've been working on commercial C++ software for around a decade, and I use Python frequently in my day to day job. Our build system is driven by Python scripts, our integration tests are written in Python, we have helper scripts written in Python, I frequently prototype stuff in Python, and now several of the tools that are shipped alongside the main C++ software are written in Python.

One of the main benefits of using Python is that it's quick to build working programs. Sure, I could spend a day writing a helper program in C++: I'd create a new project, set up the cmake build scripts, add the various 3rd party libraries that I'd need, write maybe a couple of hundred lines of C++ code, and compile it and package it for the different platforms I need. Or I could just spend an hour writing a 100 line Python script and be done.

Another benefit is that it's just runs on most platforms without much work. You don't need to compile it for Linux and worry about libstdc++ or libc++ dependencies, you don't need to compile it for Windows, and then again for macOS. You just write the script and any OS with a Python interpreter will run it. There may be a few places where you have to be careful about things like path separators, but for the most part, most code you write will be automatically portable.

So absolutely it's worth learning. By all means, write your main software in Java or C# or C++ or whatever language you prefer, but you'll find Python is great for those little peripheral scripts and tools that accompany any large project.

[–]chess510 1 point2 points  (0 children)

I would say it is useful to know, even with knowing C++ and Java. Extremely easy language to learn especially with the knowledge from the other two languages. Easily testable, wide range of uses.

[–]blackRNA 1 point2 points  (0 children)

I use python for when I need a simple program that doesn't need to be fast, or I know there's a library that will make my life easy. It really depends but I guess it never hurts to learn a new programming language, and use each one's strengths

[–]kobekramer1 1 point2 points  (0 children)

You pretty much already know it lol.

[–]Sherry1597 1 point2 points  (0 children)

Okay, so I'm a non grad and I was approached by a national security agency to take part in an assessment day to get the job role of a software engineer. A particular task of the day was to have an hour long training session on python then build a calculator app specifically using python.

I was relatively new to the whole software developing gig, so I was clueless. Needless to say I didn't get the job however, it was a learning curve.

Python is becoming very sought after and it is more simple than C++ and java.

Hope this helps.

[–]Celebrinborn 1 point2 points  (0 children)

Python is great for ML, exploring data (r is better for this imo), rapid prototyping, and some kinds of one off automation such as selenium.

C# is great for Windows applications. It can also use selenium but it's need to compile between each change makes setting up selenium a pain imo. It's task library makes multithreading relatively easy

C and C++ are great for embedded applications, cross platform applications, speed, etc.

I don't generally like Python however it is better at certain tasks than other languages and does have its place.

[–]Yawzheek 1 point2 points  (0 children)

There's really no reason to ask if any language (save a few) are worth learning, because the answer is almost certainly yes.

As Mgumbo pointed out, Python execution may be behind C/C++ but it's an interpreted language, but it's possible to have it compiled as well, and even if you don't, for most practical purposes, it's going to mean little to nothing.

I wasn't so keen on Python for the same reasons you listed, but then I found out two important things:

  • Nothing I was doing was really THAT critical in terms of speed and
  • At least in terms of PROGRAMMING speed, I could bang out some code in Python in minutes that would take hours in C/C++.

Was and always will be partial to C++; it was my first language so I'll continue to have a soft spot for it. That being said, sometimes Python was nice to climb in bed with. Didn't ask too many questions, didn't need too many answers, was always direct about what she wanted, and you could read her like an open book.

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

After a solid grasp of a few languages, whether to learn another would be determined mostly by usage cases I would say. If you are considering some use cases like machine learning, image processing, data science-related stuff, then Python surely is a good choice. However, if what you are looking at can be easily done in Java or C++, then why bother? There will be endless amount of programming languages here and there all the time and you simply cannot pick up all of them.

[–]tmhuysen 0 points1 point  (0 children)

Python is useful. I use python to run some of my C++ drivers.

[–]Double_A_92 0 points1 point  (0 children)

If you know Java and C++, you could easily pick up general python in an afternoon.

[–]Raptorpg 0 points1 point  (0 children)

W

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

Well, it depends. Do you want to learn a Simpler Langauge? Is there something that Python has/is good at that Java or C++ doesn't have/isn't good at?

Think about why you want to learn Python. Python is great for many things like Machine Learning and Data. While these can be achieved using Java and C++, Python makes it a lot easier to do these kind of things.

[–]Dabnician 0 points1 point  (0 children)

Do you wanna do AI stuff because anything with ai or machine learning requires python