What are the limits of Python?

I spent several days reading about C ++ and Python, and I found that Python is much simpler and easier to learn.

So, I wonder if it’s worth the time to study this. Or should I invest in learning C ++ at this time?

What can C ++ and Python do?

+9
c ++ python
source share
11 answers

Some limitations on Python:

- Python is slow. It can be improved in many ways (see other answers), but bare cPython bones are 100 times slower than C / C ++.

This problem is becoming increasingly mitigated. With Numpy, Pypy, and asyncio, most performance issues are not covered, and only very specific use cases are a bottleneck in Python.

- Python is open to anything. It is very difficult to protect / obfuscate / restrict Python code.

. Python is not an ad. Unlike Ruby, there is no “cool wave” around Python, and it’s even harder to find an experienced Python encoder than, say, Java or PHP pro.

- After using Python, many languages ​​seem to be painful to use. . You think this is good, but trust me, not always. When you should go Javascript after the Python project, your eyes in tears for at least 3 days. It's actually hard to get started.

- It’s harder to find web hosting than for popular solutions such as PHP.

- As a dynamic language, you do not have very convenient refactoring tools that you could get with Java and Eclipse or C # and VS.

“For the same reason, you cannot rely on type checking as a protective mesh.” This is why pythonists tend to adhere to best practices and most often write single tests than others.

“It seems I just can't find an IDE with decent code completion .” PyDev, Gedit, Komodo, SPE, etc., Just don't do it as good as it could be.

With Python 3 hints and tools like PyCharm or Sublime Text + Anaconda, things have changed a lot.

- The best documents are still available in English only. Some people can't handle it.

- You must use the syntax. Not only do you get spaces and line breaks instead of braces, but you can forget about long lambdas, -i and triple operations.

Now for me this is not a reason not to learn a tool that will make you produce more with more fun. But maybe it's just me :-)

Honestly, considering that:

  • C ++ is much harder to learn;
  • You can do almost anything you want with Python;
  • In your projects you will get faster results with Python.

If you do not have professional problems related to C ++, it is better to learn Python first, this is more motivating. You can still learn C ++ later, it is a useful language for system programming, embedded devices, etc.

Do not try to learn at the same time, multitasking rarely ends.

+37
source share

That's why it's worth learning Python:

A relatively small number of problems is limited by the speed of the algorithm. A relatively large number of problems is limited by the speed of the developer.

+31
source share

Why don't you ask the opposite question? Unlike C ++, Python can give you antigravity and invoke souls through the import command. On the other hand, C ++ "equivalent" - #include - allows you to get only boring I / O and math libraries.

Seriously though .. C ++ allows you to do lower level things, for example. kernel programming and allows you to write programs that run much faster (approximately ~ 20x). You can use it to create real threads that can take advantage of multi-shell processors, while Python ( due to its design ) can usually only run simulated threads on a single core.

IMHO, you should study both; Python for web development and fast and dirty scripts, C ++ for writing system code, desktop applications, as well as for a better understanding of the computer level at a low level. If you are just starting out, then Python; it's a lot easier to get started.

More specific velocity difference measurements can be found here.

Edit: It appears that my multithreading information is outdated; see John Polett's comment.

+9
source share

They are not used for the same things at all. Python is very useful for prototyping because it is so simple, but not always the best choice, when speed is an important factor because it is an interpreted language. C ++ can be highly optimized, but, as you said, it can be much harder to write and understand.

If you want to program systems or applications, you should learn C ++. If you program for fun and leisure, or to solve problems like http://projecteuler.net/ , then Python is also a good choice.

I personally also recommend that you first learn C / C ++ if you want to be very serious about programming, because it teaches you the important concept of memory management, which may be overlooked in managed languages.

+4
source share

if you are trying to figure out if you will be using C ++ or Python after a while, don’t take care of yourself with one language. Learn to program. Don't learn to program in <insert a language here>.

Here's an analogy: if your car is working fine (gets you where you are going, has good mileage, cheap to maintain, relatively safe), there is no logical reason to exchange it for another. None. Whatever. Bring him to the ground before you even think about what to do or model. Come on. But if you are already looking around, think about which car you’ll get, just understand this, stop asking everyone you know if you should do it. If you need to ask, you need to change it. It is as simple as that.

+3
source share

From what I was told, 1% of C ++ learning is learning C. 1% is learning additional basic functions. 98% learn to use the functions in a safe, user-friendly way and deal with the dark hairy corners of the tongue.

Learning python will teach you how to write safe and convenient code for you. I think if you learn python, go back to C ++, then you can write some good C ++ code. Of course, this does not mean that you will understand bad C ++ or C ++ code written in a non-python way.

Limits for python?

  • It is interpreted, so you need to send the source and interpreter; and the process will take much longer to start.
  • It is not C ++, so it will not play with existing C ++ code.
  • This is a bit slower (even if you apply hot contours to C). *
  • It encourages you to be “pythonic,” and some problems are easier if you are not “pythonic."

* Python may be faster:

  • Automatic GC. C ++ only works faster if it does not flow too much.
  • Dictionaries A lot of code runs in O (N plus bit), not O (N ^ 2) if you use a dictionary. Of course, you can use the hash table in C ++, but not always.
  • Memory management - The python interpreter caches some of the basic structures of data structures and then redistributes them, rather than striking the system for new memory. This reduces system calls, which is very good.
  • Profiling new algorithms is easier in python. In many problems, a better algorithm is more important than linear acceleration (which gives you C ++).
  • If you create a program that "works only once" (scientific analysis, data migration, etc.), then the compile-build-test cycle should be faster in python. It really matters;)
+1
source share

Learn a statically typed and scripting language.
You can do whatever you want in any language. A well-written C ++ code base is easier to maintain / debug than a Python code base written with the same level of competency.

If your goal is to create web content or create scripts, Python is for you. For something more advanced, C ++ is required.

As they say, go to Python.

0
source share

As others have suggested: learn Python to learn higher-level algorithms and concepts, and use them to prototype and where you can. Learn C / C ++ and / or Java for the job market and when you should use them.

Python greatly simplifies the syntax and high-level libraries, allowing you to focus on interfaces and abstractions while maintaining a functional prototype.

0
source share

One significant difference that was not mentioned above is the difference between a language like C ++, which creates its own code, and a language like Python, which by default puts a VM between you and the hardware. To perform low-level work, such as coding with the kernel of the OS, the native language will be the preferred option.

In practice, however, when you work in this context, this usually means that it completely discards C (as a portable assembler), and cannot use C ++ (and its runtime libraries), if much is not all the code.

0
source share

Comparing Python with Java, Perl, and Other Programming Languages

Professor Lutz Prechelt of the University of Karlsruhe compared Python to other programming languages. He summarizes his results: “80 implementations of the same set of requirements are compared for several properties, such as runtime, memory consumption, length of the source text, density of comments, program structure, reliability and the amount of effort required to write them. The results show that for this programming problem, which concerns string processing and dictionary search, "scripting languages" (Perl, Python, Rexx, Tcl) are more productive than "regular languages" (C, C ++, Java). In terms of runtime and consumption memory they h a hundred turn out to be better than Java, and not much worse than C or C ++. In general, differences between languages ​​tend to be smaller than typical differences arising from different programmers inside (see Lutz Prechelt, an empirical comparison of C, C ++, Java, Perl, Python, Rexx, and Tcl, IEEE Computer, Volume 30, (10), pp. 23-29, October 2000)

source link

0
source share

One thing that people often use for C, and never (as far as I know) Python, is low-level code, such as operating system kernels and firmware.

C has many constructs that make it easy, for example, to convert an arbitrary machine address to a pointer and play it out or tell the compiler that the address used for memory I / O can change, although this program does not change it or does not indicate the exact location of the object in memory. It is designed to work as quickly as possible, with little memory loss, and not safe.

This is what the comments about letting you shoot yourself in the foot are mostly mentioned.

0
source share

All Articles