The Case for Rust (in the base system)

Interesting language. lang/numbat.

Not sure how actually usable it is (as I'm not yet actually studied it), but it seems to be kinda "safe" language. It seems to free us from mangling units like km vs mile, kg vs lb, deg vs rad.

Unrelated with this thread? No, no! It's written in Rust (unfortunately for me to understand the implementation).
For many scientific computations, that would be really nice. For an inconvenient version, there are class libraries: I know one for Python, and I remember seeing one for C++ decades ago, when I was still a professional physicist. The problem here is that without language (compiler or parser) support for literals with units, the syntax gets awful. Here is what code should look like:
Code:
d = 3m  # I'm omitting the type declaration for a didactic example
x = 12mm
t = 2s
v = d / t  # The units of v should now be 1.5 m/s
r = d / x  # The result should be 25 with no units
rrr = d + t  # This should assert
but the parser would barf (*) on literals such as "3m" and "2s". So you end up having to write it like this:
Code:
d = Quantity(3, "m")
x = Quantity(12, "mm")
t = Quantity(2, "s")
Quantity v = d / t  # The result will be Quantity(1.5, "m/s")
r = d / x  # Is the type of r an int, a float, or Quantity(25, "") ?

Sadly, the number of people who really need this is small, so it's probably not worth it to add support to one of the major languages.

Footnote: That means "the parser would not be able to process ..."
 
Interesting language. lang/numbat.

Not sure how actually usable it is (as I'm not yet actually studied it), but it seems to be kinda "safe" language. It seems to free us from mangling units like km vs mile, kg vs lb, deg vs rad.

Unrelated with this thread? No, no! It's written in Rust (unfortunately for me to understand the implementation).

No reason to invent a new language.

Safely dealing with scientific units can be done (at compile time) in Common Lisp:

 
No reason to invent a new language.

Safely dealing with scientific units can be done (at compile time) in Common Lisp:

Interesting!
But the history of programming language (at least on their early ages) was to create easy-to-code languages per their use-cases, for example, FORTRAN for number crunchers, COBOL for business computing, C for writing Unix, instead of assembly languages / binary codes for each processors.

Recently I consider C without libraries (purely as language specs) as an abstracted assembly language, so compiling other languages into C is quite natural, if standard (and optional) libraries are NOT forced but calling convention per CPU. If the runtime libraries for specific languages like Rust are NOT conflict with libc and crt*.o, resulted C codes would be inter-operable with current C codes.
 
Fwiw C++ also gained some capability of writing down literals with their units:
That seems useful, and might make it possible to create a set of classes for "numbers with units" that works conveniently. I should look whether someone has done it ... but then, I'm not planning to do any programming in C++ for fun. After all, this is the Rust thread. I've actually abandoned my home rust project; it was just going too slowly, and there were more urgent projects (which either used Python, or used a tractor and shovels).
 
This is my opinion. radians is a clever may to change degrees so they can be used as arguments in mathematical functions, like sin(x). the posts before are also good ways to see then.
 
C++ actually gets better now with ranges, and all the stuff the standard library can handle for you.
I am not to worried anymore, and see Rust as a preference rather than as a complete replacement.
For memory management use smart pointers, and RAII to be on the safe site.
Some days ago I updated my C++ knowledge, and got such tips recommended.
 
Sometimes I wonder if this thread is just a dumping ground for comments on C/C++/Rust. I just don't see it as a 'conversation' any longer, but more of a reflection of what happens when people have nothing else to talk about.
 
For memory management use smart pointers, and RAII to be on the safe site.
Some days ago I updated my C++ knowledge, and got such tips recommended.
RAII solves perhaps 1% of the memory management problem in C++, and eliminates mostly just the "use null pointers and uninitialized memory by mistake" problems. And smart pointers (usually referring to ref-counting pointers that auto-delete the underlying storage when the last reference drops) also only solve a part of the problem, since they can't deal with data structures that form circular references, which exist all over the real world.

My way of summing up the problems with C++: There are whole textbooks about the semantics of move, when you call a function with a pointer.
 
Sometimes I wonder if this thread is just a dumping ground for comments on C/C++/Rust. I just don't see it as a 'conversation' any longer, but more of a reflection of what happens when people have nothing else to talk about

Please don't start war again 😂😂
Why we should speak about what we not need?
 
Back
Top