|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On May 26 2018 12:28 Liquid`Jinro wrote:Show nested quote +Python is often the first (and only) language a lot of people learn when they're really educated in something else (Like Maths or Physics) but need to make a program to do calculations for them. They often have a poor or no concept of good practices, optimisation, or how half the things they're doing even works. For instance: Deep Learning is, at the moment, almost exclusively done in Python. Not because C++ wouldn't be vastly superior for it, but simply because half the people working on it have no idea how to program when they start out, and they're just grabbing the easiest tool they can learn in the shortest amount of time.
so tl;dr: Yes. For the people not actively developing new algorithms, what would the benefit be to working in C++ instead of Python? From what I can recall, the performance of most of the computational python libraries are basically c/c++ levels of performance (since they are just calling c/c++ anyway), and can in some cases even be improved with something like cython. (I don't work in this field, just learning because I'm interested - I'm basically what you describe: only know python... and a little bit of R) EDIT: I guess basically what bo1b said already.
To be clear, the scientific python libraries have good performance since they wrap highly optimized numeric C code but it doesn't mean that a python program using them will be fast. It depends on how much work will be executed by the libraries, how much data must be transferred back/forth from python to C memory space, how much vectorization could be used and many other factors. For a different approach, have you tried Julia?
|
On May 26 2018 12:28 Liquid`Jinro wrote:Show nested quote +Python is often the first (and only) language a lot of people learn when they're really educated in something else (Like Maths or Physics) but need to make a program to do calculations for them. They often have a poor or no concept of good practices, optimisation, or how half the things they're doing even works. For instance: Deep Learning is, at the moment, almost exclusively done in Python. Not because C++ wouldn't be vastly superior for it, but simply because half the people working on it have no idea how to program when they start out, and they're just grabbing the easiest tool they can learn in the shortest amount of time.
so tl;dr: Yes. For the people not actively developing new algorithms, what would the benefit be to working in C++ instead of Python? From what I can recall, the performance of most of the computational python libraries are basically c/c++ levels of performance (since they are just calling c/c++ anyway), and can in some cases even be improved with something like cython. (I don't work in this field, just learning because I'm interested - I'm basically what you describe: only know python... and a little bit of R) EDIT: I guess basically what bo1b said already. The benefits of memory optimisation are hard to overstate, putting aside machine learning and other forms of scientific computing (which is still done in c/c++ btw, tensorflow is written in c++, even if it has an api in python), pretty much everything that is performance orientated is written in c/c++, or has an api which calls to c/c++. Any language at all which doesn't allow (and expect!) you to manually manage the memory is doing it for you, and as machine learning hasn't yet hit garbage collectors the performance losses are obscene. Take this with an enourmous grain of salt, every single one of these programs has had the books cooked:
https://benchmarksgame-team.pages.debian.net/benchmarksgame/faster/python3-gpp.html
Worth noting that for somethings memory management is not optional, I'm not sure if your learning at a university or not, but if you are, and the university is worth it's salt you'll do some operating system development, and see some practical examples of just how important memory really is.
On the other hand, there is very little benefit aside from performance that I can think of. Python is safer, faster and easier to get a program up and running then c/c++.
As an aside in theory c should compile down to a smaller faster executable than c++, yet I've noticed as the program gets more and more abstract, c++ gets comparatively faster.
As another aside, Rust is amazing, more people should use it.
|
Well, if memory optimalization is important Python most likely isnt You desired solution.That should be obvious to anyone who knows how it works. However if speed of deployment is essential Python is the way to go. Thats why its so widely used for tests.
An example: Since we work embedded most of our code is in C++ and most of our tests are in Python (even though we dont have standards for testing lanagauge and every team can chose what they want they mostly have chosen Python). So we have neatly optimazed code running on embedded product in C++ and quickly deployable tests run on PC where we dont need to worry about lack of resources. Chosing right tool for a job is important.
|
I think it's time the front page was updated tbh, is there someone I can pm with some useful resources to those thinking of studying cs?
|
On May 26 2018 09:05 nunez wrote: [..] i really dislike the built-in "shared-pointer copy semantics" of openCV.
You mean that you explicitly have to ask for deep copies of matrices? I think that's pretty brilliant since memory operations are minimized but at the same time it's one hell of a trap if someone doesn't really know what they're doing.
|
tofu is still active so hit him I guess.
Also, on the note of performance and all, it really depends on what you're working with. If you need to work with distributed systems and a lot of parallelism then it's hard to beat Erlang for example.
And I have no idea why they won't simply release a brand new C and C++ but with more friendly syntax. I mean, what matters is what it compiles down to right? Languages like Python and Ruby are also popular because they're simply a joy to write code with as you don't have to deal with metric tons of syntactic sugar and can focus on what you want to accomplish rather than how to write it properly.
The same thing in C:
int compare_int(const void* a, const void* b) { if (*(int*)a == *(int*)b) { return 0; }
return *(int*)a < *(int*)b ? -1 : 1; }
const size_t num_elem = 10; int elements[num_elem] = { 3, 6, 1, 9, 8, 2, 0, 5, 7, 4 }; qsort(elements, num_elem, sizeof(int), compare_int);
Ruby:
ary = [3, 6, 1, 9, 8, 2, 0, 5, 7, 4] ary.sort
Python:
nums = [3, 6, 1, 9, 8, 2, 0, 5, 7, 4] nums.sort()
I know this is a really bad example...
I'm by no means an expert in C but I think it could really use some library manager (like Rust's Cargo) and a good batch of standard libraries that would implement stuff that people might want to use commonly (like arrays that contain values of different types and hash tables for example).
|
That’s why you use C++
|
Sweden33719 Posts
On May 26 2018 17:14 bo1b wrote:Show nested quote +On May 26 2018 12:28 Liquid`Jinro wrote:Python is often the first (and only) language a lot of people learn when they're really educated in something else (Like Maths or Physics) but need to make a program to do calculations for them. They often have a poor or no concept of good practices, optimisation, or how half the things they're doing even works. For instance: Deep Learning is, at the moment, almost exclusively done in Python. Not because C++ wouldn't be vastly superior for it, but simply because half the people working on it have no idea how to program when they start out, and they're just grabbing the easiest tool they can learn in the shortest amount of time.
so tl;dr: Yes. For the people not actively developing new algorithms, what would the benefit be to working in C++ instead of Python? From what I can recall, the performance of most of the computational python libraries are basically c/c++ levels of performance (since they are just calling c/c++ anyway), and can in some cases even be improved with something like cython. (I don't work in this field, just learning because I'm interested - I'm basically what you describe: only know python... and a little bit of R) EDIT: I guess basically what bo1b said already. The benefits of memory optimisation are hard to overstate, putting aside machine learning and other forms of scientific computing (which is still done in c/c++ btw, tensorflow is written in c++, even if it has an api in python), pretty much everything that is performance orientated is written in c/c++, or has an api which calls to c/c++. Any language at all which doesn't allow (and expect!) you to manually manage the memory is doing it for you, and as machine learning hasn't yet hit garbage collectors the performance losses are obscene. Take this with an enourmous grain of salt, every single one of these programs has had the books cooked: https://benchmarksgame-team.pages.debian.net/benchmarksgame/faster/python3-gpp.htmlWorth noting that for somethings memory management is not optional, I'm not sure if your learning at a university or not, but if you are, and the university is worth it's salt you'll do some operating system development, and see some practical examples of just how important memory really is. On the other hand, there is very little benefit aside from performance that I can think of. Python is safer, faster and easier to get a program up and running then c/c++. As an aside in theory c should compile down to a smaller faster executable than c++, yet I've noticed as the program gets more and more abstract, c++ gets comparatively faster. As another aside, Rust is amazing, more people should use it. Yeah I know the underlying stuff is in c/c++, I just mean't that a user of them don't need to know c/c++, since it has the nice and friendly python api available.
Thanks for the thorough answer, I'm just learning on my own, I still play poker full time but have taken a bunch of intro CS/data science courses because they are interesting, and python is quite handy when you want to analyze massive amounts of data which modern poker tends to generate.
|
On May 26 2018 18:22 emperorchampion wrote:That’s why you use C++ 
C++ is atrocious though
|
The modern version of c tbh is rust, in a large number of ways. Unfortunately, I don't think it's possible to tidy up all the syntax without removing functionality an awful lot of people rely on. c++ is ridiculous a lot of the time, but a large part of the appeal is having all the functionality of any language you can think of (except modules of course) + the kitchen sink. I don't think you can have both that and simple syntax. Might want to look into std::sort as well, you can achieve a sorted array quite nicely without 10 lines of code in c++ something like this:
std::vector<int> sortThis = {3, 6, 1, 9, 8, 2, 0, 5, 7, 4}; std::sort(sortThis.begin(),sortThis.end());
The other reality is that an awful lot of people quite like the strict syntax, it's a feature to me not a pain.
Jinro unfortunately not everything is written in c/c++ with a python library attached, and for those many cases getting dirty with a lower level language is sometimes unavoidable. I also disagree to a certain degree about not needing to know the underlying library, if only because an awful lot of it is years or decades old and may not interface well with the newest version or w/e language you're running.
On May 26 2018 19:46 Manit0u wrote:C++ is atrocious though 
lol, I love and hate c++, simultaneously.
|
On May 26 2018 19:46 Manit0u wrote:C++ is atrocious though 
That's because you don't understand its beauty. I think you prefer C, and I'll be glad if I never have to depend on your code simply because of inherently easy memory leaks there. Just use RAII and <memory> and forget about 99% of memory leaks.
|
C++ is a lot of things, but safe is a word I'd avoid.
|
It's safer than C for sure. There's no discussion about it.
|
For every tool c++ gives you to be safe, it gives another weapon to shoot yourself in the foot with. There are many reasons os development is done with c, not c++.
|
I don't do OS development, but I'm pretty sure C was chosen at the time for performance reasons. C, at least at the time, was still faster than C++. Now things are a bit different, sometimes C++ abstractions are as fast as C functions or sometimes slightly faster.
Edit: Also C is smaller in size.
|
With gratuitous template usage you can make c++ faster then c, at least when the problem crosses a certain threshold of complexity. There are many reasons c++ is used pretty much universally where time matters the most, more then anything. And then there are reasons why it's not used in operating system development, many to do with run time size and how it compiles, believe it or not c++ and c do not compile to the same machine code.
Again, c++ is only as safe as you allow yourself to be, as soon as you start using templates you'll start enjoying that "safety"
|
What operating systems have been developed since C++ became popular though?
|
I'm not sure if it counts, as I'm not entirely sure on the time frame your talking here, but modern windows I think is the most likely, and it's kernel was written in c. Android is based on linux with c++ on top, but again it's kernel is in c, I'm not sure about ios and how much was based on osx, but it's written in c as well for the kernel.
I guess in terms of brand new Redox is probably the closest, written in the language I honestly expect to replace c/c++ in the coming decades.
|
On May 26 2018 08:53 nunez wrote: @excludos qt should be quarantined to the code that deals with the gui, and even there it should be used as sparingly as possible. for that it's an ok option, but for anything else there are better alternatives. if someone suggested that we use qt for signals / slots at work, he / she would also be quarantined to code that deals with gui.
some never get comfortable with the complexity of c++, and seek refuge in the abstract comfort of Qt or C# or python or whatever. parading this retreat as ersatz critique seems common.
What do you base your answer on here? Qt has loads of plugins and tools for back end purposes and is made to work equally well for that as front end. I wouldn't suggest you use it just because of signals and slots, but because it literally has an answer for all of your problems (Hyperbole of course. There's loads of things it doesn't do as well. Like heavy calculations or image operations). A lot of those problems can be solved with a external library each..or you can just remove all of them and use Qt instead. I'm also not saying it's the only tool for the job or something you must use in all situations, just that it's very good for a lot of them, and not something you should just dismiss based on..whatever you think you're basing it on. I don't know what kind of misconceptions you have about it, but I'd love to know
|
On May 26 2018 17:55 Khalum wrote:Show nested quote +On May 26 2018 09:05 nunez wrote: [..] i really dislike the built-in "shared-pointer copy semantics" of openCV. You mean that you explicitly have to ask for deep copies of matrices? I think that's pretty brilliant since memory operations are minimized but at the same time it's one hell of a trap if someone doesn't really know what they're doing.
'memory operations' are minimized? i am not suggesting making extra copies, but there are oh so many tools ready at hand for "avoiding copies" (references, an arsenal of pointer-types, containers, statics even). in most scenario's you easily get away by using the most trivial of tools (f.ex. a reference).
one only needs thread-safe reference-counting for the most complex of scenarios, and then std::shared_ptr / std::weak_ptr is ready at hand, which works for _any_ type.
types with baked-in reference-counting is haram. 'cloning' and 'deep-copy' is alien terminology.
|
|
|
|
|
|