Me Rust (the new C/C++)

ALERT: from a infant, impatient and short-attention-span rust-er/ian/... So also prone to forget things within few lunar cycles or so ;) So take with a pinch of salt.

Anyone looking at creating a new System involving new libraries and programs using C and or C++ or for that matter even Java or Kotlin or so, unless you need byte code flexibility (and in a related breath lack of source recompile to equally wide set of targets/platforms wrt Rust potentially for now), should seriously give a look at Rust and think hard before selecting C or C++ or ... over Rust.

At one end it provides the power and flexibility of C,

  • by allowing to be close to the machine and manipulate thing as required there,
  • >> with unsafe fencing to remind one self about the power and responsibility that comes with the same
  • and inturn fly rather than limp

While at the same time providing abstractions and conviniances related mechanisms of most modern programming languages like (NOTE: I would rather say, in some ways, its focused more towards end goal realisation decoupled from ideologies/methodologies/hierarchies/..., if one doesnt want to)

  • [traits] contracts/interfaces/generics/templates - the rules of engagement
  • >> if impl trait shouts at you unexpectedly, sometimes may be you are missing dyn trait
  • >> at a simple level, for now - impl for func args, dyn for data entity innards
  • [custom types] enums and structs allow one to easily create and use entities with single or multiple personalities.
  • >> even dissimilar internals can be tamed easily
  • >> cajoled into personas/masks through traits (incl operators, mem ops), auto deriving, ...
  • >> so go ahead and built your castles and or ...
  • other helpful mechanisms like
  • >> references, smart pointers (more below)
  • >> Self awareness
  • >> boiler plate avoidance
  • >> closures
  • >> macros - the potentially extra judicial and or conveniance things
  • >> iterators

Comes with a base standard library set which includes

  • common useful data structures like Slices, Vectors, Strings, HashMap, ...
  • structured and controlled memory(heap)/resource access/sharing through Box(the basic), Rc (share-readonly), Arc (share-readonly-multithreaded), RefCell (runtime flexible readwrite), Mutex (controlled-multithreaded-readwrite), Sync, ...
  • >> this is malloc-free and ipc on steriods with implicit tracking, ~0 overhead memory management, safer sharing, ...
  • >> mix and match them as required Rc<RefCell<>>, Arc<Mutex<>> could be something you may be look for sometimes
  • also has a large wild west of 3rd party modules/libraries (as with most languages)
  • >> however ideally there should be bit more standardised ones as well as structured - verified - sustained ... mechanisms. With time and more minds and hands getting in, this should improve. This is one area where if things could coalesce better, lot more domains could start using Rust, by putting some initial effort to cross the initial learning curve.
  • >>>> Beyond the initial pull of a easy interpreted environment, I feel what keeps python in the radar of many in the long run, is the large set of standardised modules useful across domains available around it. And this is one area where Go team seems to have the right thinking, in some sense, and one area where Rust may need some helping hand.
  • >> if you prefer building your own zoo over time, this shouldnt matter.

And most important of all, it allows one to be bit relaxed at some levels, by asking one to baby sit at the grass root level wrt ones intentions, so that it can baby sit the programmer at a higher level. This includes among others

  • memory ownership, borrowing and lifetime tracking with user input
  • >> these allow for safer memory access/use as well as almost 0 cost Non GC mem mgmt
  • force concious demarcating of unsafe operations like global/static entities, direct memory manipulation, inline asm, extern (handshake with other languages), ...
  • additional compiler guards include among others
  • >> initialise before use
  • >> matching which forces one to cover all possible paths as well as implicit mapping
  • >> saner data handling including integers, arrays, ...
  • standard / builtin entities and conventions like
  • >> enums like Result, Option, ...
  • >>>> remember that non closure based helpers like expect / or / ... can bite you, when used in hot path
  • >> structured and controlled resource accesss/sharing discussed before
  • clean path for recoverable errors along with support to trap panicky situations if required.
  • >> conventions prefering clear identification, propogation and handling or reporting
  • >> Rust follows the convention of better panic rather than repent, by default
  • NOTE: Remember garbage in - garbage out still holds, however the mechanisms of Rust to a great extent allow possible issues to be fenced into a smaller space for one to look at.

In your initial journey you may also encounter some of the below

  • macros like print!, format!, vec!, panic!, todo!
  • traits like Display, From(/Into), Deref, Drop, Clone (well unless you want implicit Copy)
  • directives like
  • >> derive (Debug, Clone, PartialEq, ...), auto derive useful traits for your custom entities
  • >> allow, things different from convention from above (if only the standard naming conventions were to my taste ;(, ignore potentially harmless dead code (ideally, by default, it shouldnt flag for members used in test code, if not yet in normal code), ...

There may be few oddities one may encounter here and there, which ideally shouldnt be there, but they are not show stopping. Also now that lot more entities are starting to look at Rust including linux-kernel, android, developers and inturn enterprises, ... and thus inturn more places where it will pop up, over the medium to longer run, things should mature better

Oom: Started this article to note a bit about my rust thoughts and inturn one of the outcomes of my recent rust experimentation - fuzzerk (which's partly useful for something else I am experimenting/working on, as well as in general), but given that Rust part of the note itself has become too large, fuzzerk [github-hanishkvc] pushed to another day.

Dream:ASimplerWorld(From my skewed perspective, if not anything else): If only Go, Kotlin, etal efforts switched to Rust++. Googlie Googlie. A good amount of effort has gone into these languages and some nice foundations have coalesced around them. Eqaully Rust can also get into most of these end applications places easily, if platform developer supports same.

GoGo: Also at a related but slightly different level, Go in its effort to be simple at some levels at a higher plane, may be goes beyond ideally simple rules to an extant, at a lower level. And here Rust may actually be simpler/consistent at a lower level, from a normal application level development perspective, even thou more mouthful in some ways.

PythonyVs: Given its default interpreted environment and inturn many library and program codes remaining in source format, implicitly, unless effort is put to convert it out. Its one reason as a open source enthusiast, I say dear projects continue to remain in python. While other binary world langauges and projects look at Rust also once, if not more times ;)

#rust #rustlang #modern #languages #computing #developers #computerprogramming #abstract #abstractions #memory #memorymanagement #programming #future #android #linuxkernel #paradigm #go #kotlin #python #java #c #cplusplus

Hanish KVC Menon

Systems Architect / Tech Entrepreneur / Consultant

2 年

If using expect or or or any other helper method which takes a non closure (ie like a string or so) to resolve into a valid value or to handle the error case, remember that resolving of the entity to be passed to expect or similar will occur before your happy path is taken, so you may want to use a different flow based helper in widely and frequently run code in your end use case.

回复
Ashokkumar K

Electronic Product Development

2 年

Hanish KVC Menon please add me

回复

要查看或添加评论,请登录

Hanish KVC Menon的更多文章

社区洞察