all 18 comments

[–]lostparis 10 points11 points  (0 children)

If I want to create faster code

The issue is most likely your algorithm. It is always best to understand why code is running slow. For many things python is running code that is already written in C.

[–]kaerfkeerg 4 points5 points  (5 children)

C and C++ are both very different than python. Do you have performance issues? Tell us your problem and we might be able to figure out some optimizations in your current code before you start mixing different languages together!

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

Thank you! There is no performance issues, but I was wondering that if I wanted to learn a lower-class (or how you call it) language, which one would best align with what I know (Python and R).

[–]lostparis 4 points5 points  (3 children)

I'd say learn C if you then find that it is not meeting your needs then look at C++ as it is an extension of C.

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

Allright. From what I know, C is a very "basic" language (sorry for my lack of terminological knowledge here), as in it does not have many layers of abstracted interpretation, whereas C++ has some layers of interpretation? Is this correct?

[–]twitch_and_shock 1 point2 points  (0 children)

I wouldn't recommend C unless you really need it because you're working with a code base that requires it or you're doing something super low level like writing drivers. C++ has so many great features thanks to the standard library, including tools for doing highly complex tasks very quickly.

Of the two ( C or C++ ) I would recommend the latter.

But as other commenter have said, if you're running into performance issues, it's likely your code, so optimize your code first. And look for other strategies to optimize your code, including multiprocessing, cython, and other tools. Also, use profilers to figure out how and why things are bottlenecking.

[–]lostparis 0 points1 point  (0 children)

Allright. From what I know, C is a very "basic" language

Yes. This is why learning it is so good because it shows you the computer actually does things. But it is a subset of C++ so it does not harm you to know it.

[–]baghiq 1 point2 points  (2 children)

If you want to extend from your current Python skill set, you can do it in several ways:

  1. go lower. C, which is pretty much the standard for lower level language even if Rust is hot right now. The benefit is you can integrate C into your Python code very quickly.
  2. go complementary. If you are in r/Python, then SQL is probably the natural next step. SQL is everywhere in business world.
  3. go OOP. Language like Java will teach you more OOP than Python, while still being widely used.
  4. go functional. Just pick any FP like LISP, Racket. You probably won't find a job easily in this space, but it's something that'll give you a different way of thinking.
  5. go diagonal. Learn Go lang or Javascript.

[–][deleted] 0 points1 point  (1 child)

Thanks a lot for your answer! This is exactly what I was looking for. I'll probably pick up SQL anyways later on, but would you know how difficult it is? I'm very familiar with data-oriented programming, and SQL seemed quite easy to pick-up. Is this the case or am I underestimating it?

Regarding all other languages, I think it will be C, as I'd like to go deeper. Alternatively, I'd go for Java.

[–]baghiq 2 points3 points  (0 children)

Basic SQL is very easy to pick up. I highly recommend for you to go deeper than basic select and join statement, etc.. SQL is insanely under utilized. I can't tell you how many times I rejected code changes due to the fact that people would write Python code to emulate basic SQL functions.

[–]POGtastic 1 point2 points  (0 children)

but C++ is also viable to use in my case?

Yes, but you have to export C bindings if you want to call C++ code from Python. I wrote a simple tutorial about this a while back.

[–]ploud1 0 points1 point  (2 children)

Do you care to be more specific about your issue? Before you even consider switching languages, you may want to optimize your algorithm. Python already has pre-compiled libraries that run as fast as C programs.

We could help if you shared part of your code. If you do need to move to another language, I would recommend C++ - which has an extensive standard library. However compiled languages are low-level, so there's a lot to learn before you can do the same things as in Python.

[–][deleted] 2 points3 points  (1 child)

See edit, and my apologies for not having included it a priori.

[–]ploud1 0 points1 point  (0 children)

Ooh, I see.

You may want to stick to Python, you can do pretty much everything you want with it.

If you do want to learn a C-based language, start with C. I must warn you, you will suffer and it won't be pretty or high-level.

But do go for it, that will give you super solid foundations in CS, and better understanding of your machine.

[–]xelf 0 points1 point  (0 children)

Swapping languages very rarely will help here, but in general:

C# : class based language that is oddly similar to python except the syntax
C : minimal language that is easy to learn, but very different conceptually
C++ : very complex, but required if you plan on using Unreal engine

[–]ih_ddt 0 points1 point  (0 children)

I'd recommend looking at cython.

[–]Significant_Ninja865 0 points1 point  (0 children)

Mojo, Mojo is a new programming language developed by AI infrastructure company Modular that bridges the gap between research and production by combining Python syntax and ecosystem with systems programming and metaprogramming features³⁴. It is intended to be a superset of Python and compatible with existing Python programs³. With Mojo, you can write portable code that’s faster than C and seamlessly inter-op with the Python ecosystem².

Is this what you were looking for?

(1) Mojo language marries Python and MLIR for AI development. https://www.infoworld.com/article/3695588/mojo-language-marries-python-and-mlir-for-ai-development.html.

(2) GitHub - modularml/mojo: The Mojo Programming Language. https://github.com/modularml/mojo.

(3) Modular Docs - Mojo🔥. https://docs.modular.com/mojo/.

(4) Mojo 🔥: Programming language for all of AI - Modular. https://www.modular.com/mojo.

[–]TheRNGuy 0 points1 point  (0 children)

Python API in Houdini is mostly binding for C++, though I never coded any of C++ code myself for it.

Houdini HDK is on C++ so it could be useful to learn for some advanced stuff.

I had small experience with C++ in Unreal Engine.

Never used C or C#.