Translation from http://www.livinglifefully.com/zensayings2.htm
:)
"Before enlightenment - chop wood, carry water. After enlightenment - chop wood, carry water."
After a first glimpse it’s all about structure and architecture.
After enlightenment, coding is logic again.
Seems like we lose a lot of good technology and progress for random reasons, like the “ram” of society is finite.
Sounds like the 2 hard things in Computer Science returning! Cache invalidation, naming things, and off-by-one errors. [1]
* "Knowledge is ephemeral": Cache invalidation
* "tower of abstraction": naming things, indirection [2]
Recommendations:
* "Reduce complexity, reduce dependencies": minimise entropy, maximise connectedness
* Learn: welcome newcomers; recurse to the next generation
[1] https://martinfowler.com/bliki/TwoHardThings.html
[2] All problems in computer science can be solved by another level of indirection" "...except for the problem of too many layers of indirection."
I like how he talked about using bare metal to run games and not needing an OS, relying on an ISA, or how games were easier to at one point before excessive abstractions.
One very memorable comment he made was when he was asked about what he thought about the M1 chip running software faster, his response was that we could use current hardware and make it run 100x faster if it was well written. Huge part of the many reason I switched to Linux. ;)
An example? Up above the treeline, there are communities relying on diesel for power.
Solar is a no go, with months of darkness. Wind turbines are hard to maintain at -50C, and snow and ice can impede them.
Even electric cars can only cover some of car use-cases, both due to range and refuel time issues.
Expect ICE in 2050 still.
And in most places, electric cars take petrol out of the car, and instead, see things like coal or natural gas burned, to make the electricity to charge them.
This is true, but also a good thing, while you present it as at best a wash and possibly a negative.
Coal powered EVs are better than gasoline ICEs in most situations, and nobody has a 100% coal grid anymore so the benefits are even greater. There's lots of reasons why but the main one, which is relevant to this conversation as well, is the inefficiency of ICE compared with electric motors.
Are you taking in account battery disposal?
Rule 110 is known to be Turing-complete. https://en.wikipedia.org/wiki/Rule_110
I have a feeling that Rule 90 is the most efficient algorithm: the Sierpiński Triangle, self-sacrifice, infinite recursion to a perfect pattern. I'm not mathematically talented enough to prove that though.
https://mathworld.wolfram.com/Rule90.html
Please come to chat about A New Kind of Science on Facebook! A couple of weeks ago I noticed that the page didn't exist, so created it. Hopefully Wolfram doesn't mind. We stand on the shoulders of giants.
https://www.facebook.com/A-New-Kind-of-Science-1004052657757...
Its something like the sage uncovers the boiler, points at it and announces: Look! It is a beautiful marvel of technology! Why would you want to cover it up? Look! You might learn something!
assembly instruction + machine state => new machine state
Our idea of "jumping around code" and "control flow", as in for loops or if statements, are themselves abstractions of control state (an instruction pointer) and data state (perhaps a CPU register).
So coding is really "the execution of a notional interpreter (aka semantics), then $foo." That gets to the absolute bottom of what "code" even is: instructions for an interpreting device (be it physical or mathematical).
And who says your code runs on a CPU? :^)
list.stream().filter(Objects::nonNull).map(User::getUsername).filter(Objects::nonNull).filter(name -> name.contains(searchString)).map(name -> “We have found your user: “ + name).orElse(“We haven’t found”);
Basically unreadable.
for (User user : list) if (user != null && user.getName() != null && user.getName().contains(searchString)) return “Found it!”;
return “Not found”;
Your for loop can do all kinds of damage to the list, and you have to read it all to find out what it does. Saner languages make the functional version more expressive.p:
return first(users.filter(u => contains(u.name, searchString))
I’m not saying JS is a sane language; it has an anemic standard library without a robust “first()” or “contains()”. But that code gets you the first user where the name matches, without resorting to indexes or null checks or worrying about how a for loop can mutate lists that it should not.EDIT: I should have used filter(list fn) here, I was trying to write something plausible in JS instead of a purer functional language and misses that translation.
Alas, reality, she is a cruel mistress.
So can programming in general
Which isn't a problem, because as long as its all loops'n branches, the code is easy to understand.
EDIT: “full read” includes “everywhere else this array is used, which can have far-reaching consequences if it was passed into the containing function by reference.”
Another wide-spread syntax feature is for-loops over collections like `for item in list`, again being extremely easy to read and not requiring any assignments. So, accidental in-place mutation is not an issue in practice. But, in-place mutation can be very useful to express logic in an easy to understand way.
Coincidentally my main language does not have any of these features, and in-place mutation is like 0.1% of all my problems. (And notably, memory management is < 5% of my problems).
These are all just theoretic problems, what really matters is developer experience. You can write terrible bug-ridden convoluted code in any language, ESPECIALLY with many filters and lambdas and callbacks.
The issue with the functional style is that it becomes harder to see the control flow and run-time characteristics. I'm sure functional style is great to express set operations (like DB queries) but IME they tend to optimize for source code brevity and pessimize for runtime performance.
It’s different if you’re working in lower-level code. I don’t intend to trivialize performance; the option to “go procedural” should be available. I just think it’s the wrong default. Operating systems and some kinds of Big Data need those perf boosts.
But for your run-of-the-mill CRUD app, map/filter is both clearer and safer than a for loop. Strong language support encourages this both algorithmically and syntactically—unlike what Java did, which is what I originally replied to.
Every modern language has a `for elem in range` construct, giving exactly that guarantee, as long as the element isn't a pointer.
Besides, I neither want nor need such a guarantee. There are many scenarios where in-place mutation is exactly what I want to do in a loop, and I don't want to fight the language, aka. my craftsmans tool, to do it, just because it imposes an arbitrary restriction on what I can or cannot do.
Is this a potential source of bugs? Of course it is. That's why I have tests, code reviews and debuggers.
And besides, nothing prevents me from doing the functional approach in languages like Golang, Python or Julia *if I want to*. I simply refuse to use languages that that force a paradigm on my code. This is true not only for "pure functional" languages, but also Java, which wants me to use OOP everywhere.
To me, paradigms are tools. They need to be there when I need them, and get not get in my way when I don't.
In a list
John
Jonhatan
Joy
searching for "Jo" returns all three of them in the first example, it stops when the first has been found in the second.Start including the tedious bits about adding found items to the list and the waste of intermediate variables and your "clear" code is wrapped around a lot of repetitions, that only add noise.
It just happens that you are more familiar with the second style, but pipelines are better in many other ways, clarity of intentions being one of them.
list.stream().filter(Objects::nonNull)
.map(User::getUsername).filter(Objects::nonNull)
.findFirst(name -> name.contains(searchString))
.map(name -> “We have found your user: “ + name)
.orElse(“We haven’t found”);the point I wanted to make is that the snippets presented seem carefully crafted to make pipelines look bad, but usually that's not the case.
Intermediate stream operations like map or filter are always lazy. And .findFirst() is a short-circuiting terminal operation, that does not need to consume all stream elements.
https://docs.oracle.com/en/java/javase/11/docs/api/java.base...
Truth is java streams and, even more, reactive java are the only two things that make java bearable, god save who invented them.
If I had to program java with for loops and list.add or null checks everywhere, I would probably kill myself on the spot.
But the amount of programmers taught to program like it's still 1995 it's so damn high
And I am closer to my 50s than my 40s, I can't understand why people fresh from uni say they can't understand something like
list.stream()
.map(this::maybeGetUser)
.filter(maybeUser -> userIsPresentAndNameStartsWith(maybeUser, prefix))
.findFirst()
.orElseThrow(new UserNotFoundException());
with the benefit of being lazy and only inspecting list items up to the first one that matches (and if you don't mutate any data, easily parallelizable)https://esolangs.org/wiki/Pancake_Stack Pancake stack doesn't need this hipster crap like functional programming or ifs or fors.
Optional.ofNullable(user).map(User::getUsername).map(name -> name.contains(searchString))But the stream interface is just horrible. I had to read a lot before I understood how to just filter a list and collect the results. And even after that, it still somehow didn't scream out what it was doing to me. I guess you get used to it.
users.find(_.name.contains(str))These are all from the Zen philosphy, it says:
When getting start with Zen, I see hill as hill, water as water When get experienced with Zen, I see hill as more than hill, water as more than water. When finally got mature with Zen, I once again see hill as hill, and water as water.
Basically it means that in the beginning we punch like we can.. then a martial arts student learns the proper and different ways to punch.. so a punch is no longer just a punch... Is a lot of instructions.. Then to sheer practice and repetition the right way to punch becomes second nature.. so the right way to punch is the only way so it's only a punch again.
So coding it's just ifs and loops... Then is OOP and Functional and Logic... But then once you transcend all those paradigms you understand that is all ifs and loops.