Why concatenate at all? It’s overrated (often not needed) and slower than e.g. if you can do:
julia> println("I'm on ", "cloud ", 9)
I'm on cloud 9
It’s superficially similar but not the same as:
Note, you can most often change commas, as there the first one, to *, e.g. while doing using println
, but not for the latter, since * only joins strings, not numbers, on either or both sides. String interpolation is another option, but also slower (while handy), since, I believe, it does an implicit concatenation.
C++ has >> (and <<) for streams, hacking those shift operators to do different things, e.g. when printing…
Yes, you should know about * for concatenation (and ^ the logical extension of that, though rarely used) at least to know both for reading other peoples code, but I wouldn’t even teach it first as something important, since concatenation is far from free in any language. So if you can simply print the strings separately in order as I did, without concatenating first, it’s faster (less tress on the garbage collector, also a reason to prefer << in C++).
if you want to only join, not print you CAN do cat_string = string("I'm on ", "cloud ", 9)
, or alternatively join(["I'm on", "cloud", 9], " ")
.
Such is logical to me, and when you need to join with a separator above, it’s completely illogical to me in Python:
>>> " ".join(["Hello", "world!"])
'Hello world!'
If that’s natural to you then it’s only single dispatch bias that was beating into you!
Why is there no short and simple floor division operator like in Python //?
It’s been answered what the alternative is, but why not? It isn’t a hugely used operator, and // is taken for rational in Julia (while maybe not used a lot, they are useful and could be used more often, can be made faster and then maybe they will be used more…they are they’re the default in Raku, former name Perl 6). I can easily justify / being a regular (float) division, that’s what you use usually, much more important, why Python 3 changed to that from integer division of Python 2.
Many language, also e.g. MATLAB is 1-based, I support that, but note Julia also supports 0-based (though a package), or arbitrary. You most often shouldn’t care, and use begin and
endand
eachindex` (at least in generic code, packages for others).