Could you make proper monoid out of Julia ranges? What would be a unit in that monoid? Could you tell me how empty range looks in Julia (in Python/C++ it looks trivial)?
> Python cannot even index lists by ranges (or other lists)
sure, Python has deficiencies as well.
C++ STL iterators/ranges are made in the same way, and for a good reason - composability first. It described very well in Alex Stepanov book (https://www.amazon.com/Mathematics-Generic-Programming-Alexa...), as well as how it helps when we move to parallel algorithms (http://stepanovpapers.com/p5-austern.pdf).
It is even more explicit in upcoming Ranges library in C++20
If you can understand how to use the STL properly, you're well on your way to becoming a profiicent C++ programmer.
His books are fantastic too.
Elements of Programming:
and From Mathematics to Generic Programming:
If you prefer video lectures, his second book is based off his lecture series Four (three) Algorithmic Journeys:
It's a combination of history and math/algorithms and programming (using C++). If you're just looking for a straight intro to C++ course this isn't it. But it's a ton of fun and the generic programming/STL mindset is very powerful.
Programming Conversations is another great lecture series by Alexander Stepanov:
I would also recommend searching YouTube for videos by Sean Parent. This one in particular is very enlightening:
Sean Parent is very good at getting you in the STL mindset and showing off the expressive power of using the standard STL algorithms in your code. Except in the simplest cases, you should try to use them instead of writing your own loops.
Here are some random tips if you're coming from C or Java:
"new" is not the way to create objects in C++. new and delete should almost never be used by serious programmers in C++. Never use new and delete (or malloc and free). If you want a dynamically-allocated array, use the standard vector.
It's much easier to write C++ than it is to read it. This is because you can always write using a simple clear subset of C++ that you understand. Try to pick a style that you think as many people as possible will understand. Programming languages are for humans to read. I try to write code that I think C programmers can read.
Edit -- Another tip:
Exception safety isn't about C++'s exception-handling language feature. Exceptions still happen in C. There's just not a language feature that directly expresses them.
Writing exception-safe code is nearly impossible in C. RAII and C++'s built-in exceptions make it possible. If you're careful to always use RAII by default, you can get the basic exception safety guarantee automatically without thinking about it. And you can get the strong exception safety guarantee whenever you need it.
The thing about advanced maths is that it forces you to think about abstractions in ways that not even programming forces you to think. You can get pretty far programming without much abstraction, but you can't understand the mathematical fact that any group of order four is either cyclic or isomorphic to the Klein-four group without thinking in a really abstract way. The more you study these abstractions in advanced maths, the better you get at thinking in an abstraction-first way.
A great book that just came out this year explains this really well by taking you from a basic algorithm to an abstract implementation, explaining the maths along the way (from multiplication to abstract algebra and number theory). It's titled From Mathematics to Generic Programming and I recommend it to anyone who wants to understand more of what I mean.
Get dozens of book recommendations delivered straight to your inbox every Thursday.