3 ms·
You already have a lot of good answers, here's some more: C and C++ really isn't the same thing. Certainly not "modern" C++. Unless you know of any C++ project
by e12e 11y ago
You already have a lot of good answers, here's some more:
C and C++ really isn't the same thing. Certainly not "modern" C++.
Unless you know of any C++ projects/frameworks/libraries you really want
to use/contribute to -- I don't think I would recommend looking to hard
at C++. It certainly isn't a dead language, and has many uses -- but at
least outside of the gaming industry, I can't think of any segment were
C++ would be the preferred language -- except when dealing with legacy
code (which of course, realistically is the biggest segment...).
Perhaps C++ paired with qt for GUI programming.
But even for games, you don't need C++ -- if you are free to start
from scratch anything will work.
> is Rust a decent place for me to learn lower-level concepts
Which lower level concepts?
C maps quite neatly to assembler -- but to appreciate that I'd recommend
learning a bit of assembler. amd64 with nasm/intel syntax is rather
pleasant[1]. It'll let you see what calling conventions/ffi, data layout
and the difference between c-strings and pascal strings are all about.
If you take a canonical hello-world from C, C++ and rust and look at the
generated assembly -- rust and c++ will be (IMNHO) closer to each other
than to C. The assembler generated by the c-compiler will be straight
forward, and quite readable -- while both C++ and rust will look a
little more convoluted. (This is also true for Nim, which compiles to C
-- but needs it's own runtime. I've not looked too hard at code
generated by go -- but given the runtime, I think that assembly would
also be much more difficult to make heads and tails of, than something
output by a C compiler).
If your goal is more to learn a low-overhead compiled language, I would
recommend rust. If your goal is to find a compiled language that is easy
to integrate with others, I think I would recommend C (for now) -- and a
bit of basic assembler.
I think after learning a bit of assembler and C -- one also gets a
better appreciation for why Pascal was so popular for a while.
With any luck, and more work -- hopefully rust will be able to sneak
into quite a few of Cs use-cases, like writing libraries for easy
consuption by python/ruby/etc. But I don't think rust is quite at a
place where it makes sense to reccomend it for that use-case to a novice
(low-level) programmer. I'd love to be wrong about that.
[1] Unfortunately, I don't really know of any good introductions to
amd64 assembly. There are a couple of great tutorials for 32bit/x86 --
but a lot of things are simpler in our amd64 world. While it might be
good to know how to write bootloaders (16bit) and 32bit code -- I'd love
for there to be a simple tutorial focused on just amd64.
I like this asm tutorial (unfortunately for 32-bit):
http://www.drpaulcarter.com/pcasm/ http://www.drpaulcarter.com/pcasm/
And "HLA" is another great resource for 32-bit assembler:
http://www.plantation-productions.com/Webster/www.artofasm.com/index.html http://www.plantation-productions.com/Webster/www.artofasm.c...
Sadly, neither have been ported/updated to a version with a focus on amd64 only.
Intel has an ok overview article focused on 64-bit:
https://software.intel.com/en-us/articles/introduction-to-x64-assembly https://software.intel.com/en-us/articles/introduction-to-x6...
- steveklabnik 11y ago> But I don't think rust is quite at a place where it makes sense to reccomend it for that use-case to a novice (low-level) programmer. I'd love to be wrong about that. Can you expand on why that is, maybe?
- e12e 11y agoWell, right now -- as a novice -- I could take a look at: http://cffi.readthedocs.org/en/latest/overview.html#simple-example-abi-level-in-line http://cffi.readthedocs.org/en/latest/overview.html#simple-e... And, under IPython (python3) on Windows (I already had ms visual studio installed): import pip pip.main("install cffi".split()) > (...) > Successfully installed cffi-1.0.3 pycparser-2.13 from cffi import FFI ffi = FFI() ffi.cdef("""int printf(const char *format, ...); """) C = ffi.dlopen(None) arg = ffi.new("char[]", b"world") C.printf(b"Hi there, %s!\n", arg) > Hi there, world! > 17 So a lot of this is tooling, integration and documentation. If one might whip up something similar for rust that works cross platform, and results in code that is reasonably easy to distribute via pypi (and similar for gems for ruby etc) -- that'd be great. So, I meant that for a novice, that wants to, say write a compiled extension/wrapper for python/ruby whatever -- a bit of C and the standard docs go a long way now. Obviously there's a lot of work to get to the point of C (it's been ubiquitous for a while...) -- but if some parts could be made similarly accessible; interfacing with rustc, if rustc is in path/installed "properly", some magic on the host-language side etc -- that would be very good, I think.
- steveklabnik 11y agoCool, thanks for elaborating :) I put the basics into our docs: http://doc.rust-lang.org/book/rust-inside-other-languages.html http://doc.rust-lang.org/book/rust-inside-other-languages.ht... , but it is just the very basics.
- e12e 11y agoThis great! Looks like there's still a bit of a gap wrt passing arguments; like the snippet above does. After skimming the chapter on ffi as well, there appears to be the need for a bit of experimentation (for me/a novice) to get that to work (eg: passing in a string, getting it back reversed, or as a list/array of unique characters/glyps etc). I'll have a look when I find the time - but this is a great start!