(In fact I try to avoid writing C or C++ whenever possible these days; undefined behavior in the language is too pernicious and unfixable without breaking compatibility. I think both languages are approaching obsolescence.)
(In fact I try to avoid writing C or C++ whenever possible these days; undefined behavior in the language is too pernicious and unfixable without breaking compatibility. I think both languages are approaching obsolescence.)
One advantage to being an older programmer is I don't feel any need to show off any more. I try to make it so obvious that anyone would look at it and think that's so simple, anyone could do it.
It's surprisingly hard to write simple code. Any idjit can come up with Rube Goldberg code.
Are you thinking more of JS or another functional scripting language than C/C++? C doesn’t have map, so it’s not an option, and in C++ it’s called something else.
In JS, I so wish that I could switch to functional constructs like map permanently, but map and foreach are much slower than loops, an order of magnitude or more for tight loops. I’m still forced to use loops in performance critical code, even if I consider map a better choice.
Coming back to C++ after having been in JS land for 5 years, C++ feels constantly difficult to use, and all the names for the functional primitives don’t seem to make intuitive sense like they do in JS.
I just learned this about JS's map/foreach a few weeks ago. I didn't think it was possible to be more disappointed by JS than I already was, but somehow I managed it.
I don’t think I’ve ever written one correctly on first try.
#include <stdbool.h>
#include <stdio.h>
typedef long T;
bool find(T *array, size_t dim, T t) {
int i;
for (i = 0; i <= dim; i++);
{
int v = array[i];
if (v == t)
return true;
}
}
There are 5 errors in that example.Because this is crazy to me! Some languages only use for loops (Go).
Please don't take offense, but this is odd to me. I honestly severely doubt I am some sort of programming super genius, but I have never had any issues setting looping logic correctly. (I took four years to teach myself programming & CS and now I've been at my first professional dev job for ~6 months.) None of my colleagues seem to have such issues either. What are you experiencing trouble with most? Off-by-one?
It's usually much easier to take extra time to make sure it's right than to debug it later.
But yeah, syntax (what order the arguments go in) and off-by-one issues are the majority, I think. Plus figuring out what my initial accumulator needs to be.
Idk, map/filter and friends are just a much more direct mapping of how I think of programming.
Or maybe I’m misunderstanding the use case?
Functional graph programming is also still a bit of an open problem. There are awkward scenarios in both cases.
Not sure how you deal with that with for loops either. Increment the iteration var in the body of the loop? (Seems scary to me, but like I said, I’ve got terrible intuition with them)
var ie1 = foo.GetEnumerator();
var ie2 = bar.GetEnumerator();
while(true)
{
var has1 = ie1.MoveNext();
var has2 = ie2.MoveNext();
if (!has1 && !has2)
break;
if (has1)
// do something with ie1.Current
if (has2)
// do something with ie2.Current
}C++ only when Java or .NET need it's assistance, or integration with OS APIs that require C++ (NDK, WinUI, DX).
Then C only when there is no alternative (customer wants it, we only do C here, required lib is C only e.g. SDL, ...).
It is an herculean project, but maybe some day LLVM could be rewritten into something else. After all it isn't the first compiler stack, just the one that got most famous.
Microsoft says the future is a mix of constrained C++ (Core Guidelines), Rust and AOT C#.
Google says the future is C++ and Java (as of Treble) on Android, with Go, C++ and Rust on ChromeOS and Fuchsia.
ARM says C++ on mbed.
GenodeOS says C++ and Ada.
Newton, Symbian, Bada and BeOS used C++.
C is married with UNIX, they were born to each other, other OSes have long followed other paths.
Apparently they are also adding support for desugaring Java 10 language features (yep 10 not 12) that don't rely on new JVM bytecodes (as per Google IO talk about state of Android tooling).
At least for now.
The features required are still unstable (as in not in the stable version of the compiler), but it’s getting there, and doing it fast.
In any case, firmware behaves a lot like banking software, language change will take time
Also, most toolchains of the sector are way more complex to maintain and way more bloated.
Astrobe has been selling development kits for ARM based boards for years now.
But yes, Rust, or even in userspace, as newer and/or more microkernel-ish OS's allow for. Apple is doing work to allow drivers to be written in Swift...
Some device classes (not to mix with OOP ones) can only be programmed with C++, while others can be developed in any compiled language able to link to the OS APIs.
There is a WWDC session on it.
Rust does not have these same features to date.