Ideas from Other Languages
Almost every idea comes from somewhere, but some are clearly inspired by a particular language or developer. Several of these ideas have been adopted, some not.
Circle (Sean Baxter)
- Fix C++’s “wrong defaults”
Sean Baxter writes about C++:C++ has a number of “wrong defaults,” design decisions either inherited from C or specific to C++ which many programmers consider mistakes. They may be counter-intuitive, go against expected practice in other languages, leave data in undefined states, or generally be prone to misuse.
I am not familiar with all of these issues, but in a new language we certainly could fix a lot of it.
- Uninitialized automatic variables.
- Integral promotions.
- Only allow safe ones,
otherwise an explicit cast is necessary.
- Only allow safe ones,
- Implicit narrowing conversions.
- Not allowed,
only implicit widening is allowed. - Assignment of integer and float literals to variables of certain precision is only possible if “it fits”.
- Not allowed,
- Switches should break rather than fallthrough.
- Use the keyword
fallthroughinstead, as in Swift.
- Use the keyword
- Operator precedence is complicated and wrong.
- If the suggestion of Circle (Sean Baxter) works well, then that would be fine.
- Cpp2 (Herb Sutter) has this precedence.
- Hard-to-parse declarations and the most vexing parse.
- Use the keyword
func(but not typicallyvar, unless you want type inferring)
- Use the keyword
- Template brackets
< >are a nightmare to parse.- I would not like to change this, only if it really has to be.
- Cpp2 / Herb Sutter kept
< >after all.
- Forwarding parameters and
std::forwardare error prone.- I am not familiar with the problem(s), but Cpp2 / Herb Sutter offers the
forwardkeyword.
- I am not familiar with the problem(s), but Cpp2 / Herb Sutter offers the
- Braced initializers can choose the wrong constructor.
- Do without braced initialization altogether.
- With the keyword
functhere is now a clear distinction between function declaration and variable declaration with initialization. - The classic initialization via
(...), ultimately a function call of the constructor, is a better fit anyway.
- With the keyword
- Braces / curly brackets only for initializer lists,
- only when a constructor or assignment operator is defined, with
InitializerListas input parameter, - i.e. for tuples, lists etc.
- only when a constructor or assignment operator is defined, with
- Do without braced initialization altogether.
0shouldn’t be a null pointer constant.- Not allowed, use
NullPtror explicit casting.
- Not allowed, use
thisshouldn’t be a pointer.- Better
thisis a reference.
- Better
- Versioning with feature directives
- Standardization is better than having multiple different language “dialects”
but- for transitioning existing source code and
- for the evolution of a language
- it is a very interesting idea to selectively enable new language features or defaults.
- Standardization is better than having multiple different language “dialects”
- Circle C++ with Memory Safety
- Extending C++ for Rust-level safety.
Cpp2 (Herb Sutter)
- is
- as
- Function Parameter Passing
in,inout,out,move,copy,forward- I like this and therefore “copied” it.
- Labelled
breakandcontinue(i.e. multi-level)outer: while true { j := 0; while j < 3 next j++ { if done() { break outer; } } } for words next i++ do (word) { ... word & i ... }iterates over all words and with an index, at the same time.- Uniform Call Syntax for member functions and free functions.
- Function Bodies
multiply: (x: int, y: int) -> int = x * y;multiply: (x: int, y: int) x * y;(not even an=anymore?)multiply: (x: int, y: int) -> int = return x * y;- Nice and short, as in math, but
- actually not quite as in math, as math usually does not denote the type,
- in the end it is one more kind of notation for functions.
- Implicit Move on Last Use
- So resources are freed even earlier than in C++.
- Named Return Values
- Inspect, a kind of pattern matching.
- Unified
operator=for assignment, constructor, and destructor).- Takes a bit of getting used to.
Rust
- Security, of course: borrow checker etc.
- Ranges
Julia
- “Cilia” sounds like something in between C/C++ and Julia, so maybe I could/should add some more of Julia’s interesting features to the Cilia wish list.
- Julia has very strong math support. Some of its features should be easy to copy.
b = 2aas short form ofb = 2*ax ÷ y, integer divide, likex / y, truncated to an integersqrt(x),√xcbrt(x),∛x!=,≠<=,≤>=,≥- Operator overloading
- See:
- www.geeksforgeeks.org/operator-overloading-in-julia/
- „Precedence and associativity: When defining new operators or overloading existing ones, you can also specify their precedence and associativity, which determines the order in which they are evaluated.“
- That seems quite complicated to parse?!
- I cannot find any other reference to this feature, I assume it is a misunderstanding.
- „Precedence and associativity: When defining new operators or overloading existing ones, you can also specify their precedence and associativity, which determines the order in which they are evaluated.“
- github.com/JuliaLang/julia/blob/master/src/julia-parser.scm
- www.geeksforgeeks.org/operator-overloading-in-julia/
- Much more operators
- See:
- Many kinds of brackets?
- stackoverflow.com/a/33357311
- TODO: Are these “unusual” brackets meant to be used as operators?