News for hackers. Stuff that matters.
Re:“Coding is basically just ifs and for loops.” by ncann on Saturday December 04, 2021 @01:19PM (#29442930)
That first reply is so funny to me because it hits too close to home

https://twitter.com/nice_byte/status/1466940940229046273

The more I do this, the more I gravitate towards the simple things.

Re:“Coding is basically just ifs and for loops.” by freyir on Saturday December 04, 2021 @03:29PM (#29444024)
New developers write simple but shortsighted code. It gets the job done, but it will be painful to work with in the future.

Intermediate developers, bitten by their past mistakes, decide to future proof their work. But they don’t just look one or two steps ahead, rather they try to look five steps ahead and identity problems that do not and may never exist. Consequently, they over-engineer, over-abstract, and over-complicate everything. Carmack’s recent “But here we are” speech resonated with me.

Advanced developers identify the right balance for each task between simple and complex, concrete and abstract, and pragmatic and idealistic. In my experience, they favor simple and pragmatic solutions, use abstraction effectively, and can satisfy near-term goals quickly without painting themselves into a corner. “As simple as possible, but not simpler.”

I try to avoid working for tech leads stuck in the second phase, which is not uncommon. If you suggest taking the “ifs and for loops” approach of solving a simple problem with a simple solution, they’ll assume you’re on the wrong side of the bell curve.

Re:“Coding is basically just ifs and for loops.” by pkukkapalli on Saturday December 04, 2021 @05:03PM (#29444702)
Had a boss once who insisted that all if statements should be pushed out to factory classes, and all control logic should be done by constructing a different instance of an interface. It was a pretty rigid system, but at least it did force me to write small focused classes that were easy to test.

Debated for a long time whether that methodology was stuck in the second phase or if it was actually the third. Still don't have an answer, but these days I think having a plan is better than just letting engineers run roughshod, as long as the conventions are easy to follow.

Re:“Coding is basically just ifs and for loops.” by ncann on Saturday December 04, 2021 @09:12PM (#29446167)
That just sounds like enterprisey Java to me, which I firmly believe is closer to 2 than 3.
Re:“Coding is basically just ifs and for loops.” by tambourine_man on Saturday December 04, 2021 @05:38PM (#29444949)
Programming alone vs programming in a team are very, very different occupations. A lot of what applies to one doesn’t apply to the other. I’m still painfully learning this, after all these years.
Re:“Coding is basically just ifs and for loops.” by bradrn on Saturday December 04, 2021 @08:08PM (#29445866)
Could you elaborate please?
Re:“Coding is basically just ifs and for loops.” by atomicnumber3 on Saturday December 04, 2021 @09:51PM (#29446330)
I think it comes down to there being two kinds of codebases...

In the first kind, all relevant developers have deep expertise in the system, or build towards having deep expertise. There's an expectation that flexible abstractions will be used, not abused, unless it's one of those scenarios where the use outweighs the abuse. The abstractions are tomato cages, and they're there to support the system as it grows, provide some structure, but not to strangle it.

In the second kind, the default expectation is that a developer will have little to no familiarity with the system, they will be isolated from it as much as possible, and they will be given such a tightly constrained sandbox that they can't break anything outside it. You will write your little plugin, or whatever, get in and out, and you're done.

These can both be useful kinds of systems/codebases in orgs of any size. The first kind of codebase can enable an experienced team to move really fast and be extremely productive. The second kind of system can help lots of different teams of different skill levels jump in and leverage your system with little required knowledge, and thus be productive that way. So there's really no way to say one of these patterns is good or bad.

But in general if you churn in and out a bunch of replaceable cog code monkeys, probably low-paid, the second kind of system just ends up working better. Giant "enterprise" software shops like parent poster aluded to typically end up in this kind of high turnover scenario after enough finance/MBA people have been brought in, hence their bad rap.

Re:“Coding is basically just ifs and for loops.” by tambourine_man on Saturday December 04, 2021 @11:30PM (#29446694)
I have much more experience working alone, but: git alone is a breeze. I don’t need to impose myself some arbitrary constrain because I know (or think I do) I won’t abuse it. I can use the stack I consider best/am more productive on, instead of what’s fashionable this year. No linting, coding conventions, etc. Just the pure joy of problem solving.

On the other hand, on the right conditions, the amount you learn on a good team is ridiculous compared to what you’d do alone. Weeks vs years kind of thing.

Re:“Coding is basically just ifs and for loops.” by astrange on Sunday December 05, 2021 @03:33AM (#29447743)
The key insight to "at least destroying your architecture makes it easy to unit test" is that being able to unit test is not actually that important. There's other kinds of testing out there!
Re:“Coding is basically just ifs and for loops.” by KineticLensman on Saturday December 04, 2021 @04:34PM (#29444519)
Q: What's the difference between a novice and an expert?

A: The novice thinks twice before doing something stupid.

Re:“Coding is basically just ifs and for loops.” by rackjack on Saturday December 04, 2021 @06:00PM (#29445096)
I don't understand this saying.
Re:“Coding is basically just ifs and for loops.” by Jensson on Saturday December 04, 2021 @11:03PM (#29446602)
Often doing the stupid thing is the right thing to do, instead of thinking hard to do the smart thing that ultimately wont be needed and will be harder to understand.

So juniors thinks twice before doing stupid simple stuff. Intermediates thinks twice and does smart stuff. Seniors only does smart stuff where it is needed and does the stupid simple stuff without thinking in most places.

Re:“Coding is basically just ifs and for loops.” by bryanrasmussen on Sunday December 05, 2021 @01:17PM (#29451383)
well actually I am not familiar with the phrase before, so maybe KineticLensman knows the proper meaning.

That said for that specific meaning I would prefer something like - The novice fears simplicity.

Maybe throw in a - The expert loves it - at the end.

Re:“Coding is basically just ifs and for loops.” by bryanrasmussen on Saturday December 04, 2021 @06:07PM (#29445147)
when the expert thinks twice they don't do something stupid?
Re:“Coding is basically just ifs and for loops.” by doubled112 on Saturday December 04, 2021 @08:04PM (#29445843)
That's not how I interpreted it at all.
Re:“Coding is basically just ifs and for loops.” by feoren on Saturday December 04, 2021 @09:08PM (#29446147)
"It's common to become very good at doing it badly"
Re:“Coding is basically just ifs and for loops.” by wruza on Saturday December 04, 2021 @11:08PM (#29446618)
There is another important difference: the expert thinks twice before doing anything at all.
Re:“Coding is basically just ifs and for loops.” by dekervin on Saturday December 04, 2021 @04:32PM (#29444504)
And that's also why a lot of Architecture Astronaut that looooved Java, didn't see Python coming.
Re:“Coding is basically just ifs and for loops.” by hiram112 on Saturday December 04, 2021 @05:22PM (#29444847)
Funny, I took over a modern python service and I was pretty shocked at what I inherited. Long gone are the days of "There's one way to do things".

Instead, this thing would give the most "enterprisey" Spring JEE application a run for its money with its endless annotations, dependency injection magic, all sorts of pseudo-types - both the "built-in" Python 3 ones like Set and List, but also the libraries like Pydantic. But unlike Java, these types aren't even really guaranteed by the language at compile time, so even if your IDE plugin can successfully detect them, things will still (silently) slip through at runtime.

The async functionality that's been bolted on to the language is worse than even the old and confusing Java multi-threading primitives, and the funny thing is it still doesn't actually run things in multiple threads. For that, your simple Rest API is running on layers of C programs like Uvicorn which itself is then wrapped by another few processes running Gunicorn which in turn is probably running behind NGINX. LOL, and we thought the Servlet stuff with Tomcat and JBoss was clunky - this is insane.

To be honest, if there ever was a sweet spot for Python, it would have been for smaller code bases that weren't complex enough for big "enterprisey" langs like .Net or Java, but were more permanent and complex than shell scripts or (back in the day) Perl could handle.

But nowadays, I don't think modern Python fits any use case real well. It's still dynamically typed, slow, single-threaded, and has a poorly managed ecosystem and hodge-podge of tools like virtualenv, pyenv, poetry, etc. that never quite become standardized and stable.

So unless you've got a bunch of Python experts who aren't interested in moving to a better lang, I'd find it hard to go with Python for new projects.

Re:“Coding is basically just ifs and for loops.” by ahdh8f4hf4h8 on Sunday December 05, 2021 @11:45AM (#29450572)
> ...endless annotations, dependency injection magic, all sorts of pseudo-types

This sounds like what happens when a bunch of Java/C# developers jump over to python without learning the "python way" - this is more related to the developers than the project

> But nowadays, I don't think modern Python fits any use case real well

Python has effectively taken over the data science / machine learning space. For most use cases, the algorithms are massively more important than the language.

> poorly managed ecosystem and hodge-podge of tools like virtualenv, pyenv, poetry, etc. that never quite become standardized and

This is true, but Java and C# also have many issues in this respect. The move from Java 8->11 is particularly painful - many fundamental libraries related to security or connection handling were not backwards compatible. Many libraries now require multiple branches for different JDK levels. Maven and Nuget are about as good as pip - they all have weird edge cases.

I use both Java and Python on a daily basis - each has their strengths and weaknesses. Java is great if need long running processes with weeks/months of uptime, Python is great for backend data manipulation and analysis.

Re:“Coding is basically just ifs and for loops.” by the_gipsy on Saturday December 04, 2021 @06:40PM (#29445342)
Long gone are the days when Python was a hacker tool. It’s been an enterprise thing since startups got wind of the fact that it could be used to attract programmers, to attract VCs.
Re:“Coding is basically just ifs and for loops.” by GhettoComputers on Saturday December 04, 2021 @05:11PM (#29444756)
Recently posted this, which wasn’t well received.

https://motherfuckingwebsite.com/

Where does this fall?

Re:“Coding is basically just ifs and for loops.” by viraptor on Saturday December 04, 2021 @05:34PM (#29444928)
In going too basic. We can go to simple and elegant without going all the way back to crappy stone tools.

http://bettermotherfuckingwebsite.com/

https://evenbettermotherfucking.website/

Re:“Coding is basically just ifs and for loops.” by Aeolun on Saturday December 04, 2021 @06:40PM (#29445352)
It’s interesting that on mobile the original one is actually nicest (to me).
Re:“Coding is basically just ifs and for loops.” by bobthepanda on Sunday December 05, 2021 @03:40AM (#29447770)
right, the problem is that on wide displays we really aren't meant to read, say, 27 inch-wide columns of text.

The silly thing is that it's literally one CSS property, max-width, that takes care of that problem.

Re:“Coding is basically just ifs and for loops.” by GhettoComputers on Saturday December 04, 2021 @05:52PM (#29445050)
Thanks for that link! I actually like the other one much more. I really appreciate JS free sites, Amazon can be used without JS for example.
Re:“Coding is basically just ifs and for loops.” by betaby on Saturday December 04, 2021 @05:39PM (#29444957)
That site is a piece of shit, because it uses google analytics, thus snitches to a big brother.
Re:“Coding is basically just ifs and for loops.” by GhettoComputers on Saturday December 04, 2021 @05:53PM (#29445055)
You’re right, I didn’t notice! Gonna link to evenbettermotherfucking.website from now on.
Re:“Coding is basically just ifs and for loops.” by theshrike79 on Wednesday December 08, 2021 @03:18AM (#29482339)
I'm currently working with a team of Advanced developers for the first time in my career. Nobody is padding their CV with fancy shit. Everyone has gotten the "new shiny" out of their system.

Everything is as simple as it can be, no simpler and no more complex. Sometimes a bunch of flat JSON files in an S3 bucket is enough of a database, you don't need a 42 machine Aurora cluster.

All fancy "Machine learning" stuff really is just a bunch of ifs and for loops internally :D

Re:“Coding is basically just ifs and for loops.” by dls2016 on Saturday December 04, 2021 @09:53PM (#29446339)
> Carmack’s recent “But here we are” speech resonated with me.

Watching this right now and all I can think about is Microsoft Bob.

Re:“Coding is basically just ifs and for loops.” by systemvoltage on Saturday December 04, 2021 @04:02PM (#29444283)
Well said, this hits home. Also constant refactoring and maintenance of the codebase without adding any new features.
Re:“Coding is basically just ifs and for loops.” by firebaze on Saturday December 04, 2021 @04:09PM (#29444329)
Bull's eye.
Re:“Coding is basically just ifs and for loops.” by reikonomusha on Saturday December 04, 2021 @01:37PM (#29443140)
Despite being a joke, I know it's the "Ha Ha Only Serious" [0] sort. I can't help but think this is severely biased by the trends of "enterprise software," where you eventually "give up", and clock your 9–5 writing if+for making a fine living, but erroneously pass that off as a mature, Jedi-like way of thinking about programming, like the meme suggests. (And, consequently, you spend no less time debugging hairy, nested, imperative conditionals with for-loops that are off-by-1.)

I have no beef with if+for, but a large part of the reason they're "goto tools", if you will, is because industry is slow to assimilate many state-of-the-art ideas, sometimes by as much as 40 years.

Simpler building blocks does not necessarily mean simpler solution. If only!

[0] https://en.m.wiktionary.org/wiki/ha_ha_only_serious

Re:“Coding is basically just ifs and for loops.” by xyzzy_plugh on Saturday December 04, 2021 @02:02PM (#29443374)
> you eventually "give up", and clock your 9–5 writing if+for making a fine living, but erroneously pass that off as a mature

This comment sure indicates to me where you most likely are on the curve.

In all seriousness, I think this is considerably off the mark. After enough experience you realize that expressivity and convenience are antipatterns and don't actually simplify things but are harbingers of complexity, bugs, tech debt, even the downfall of organizations and products.

Saying it is all ifs and for-loops is completely true. Everything else, all the abstractions and high level features, are just sugar.

I try to keep a healthy and balanced diet, myself.

> industry is slow to assimilate most state-of-the-art ideas, sometimes by as much as 40 years.

Most of those ideas are terrible. The industry is so incredibly young and has experienced so much change over those 40 years that I have a hard time accepting the notion that the industry is slow to adopt. The reason the old building blocks are still popular is because they are a thin abstraction over how computers work, and ultimately that is at the root of everything we do.

Re:“Coding is basically just ifs and for loops.” by reikonomusha on Saturday December 04, 2021 @02:06PM (#29443403)
Really, there are no if+for, just compare and jump. Why don't we use what the metal uses, instead of these "expressive abstractions"?

If+for have no deeper foundational significance in the construction of programs or computations, literally, than say a lambda function. But because the latter is unfamiliar, it's spoken about in the same manner you present: as if it is some highly abstract, complicating, high-level feature (when truly that take is just baloney).

Re:“Coding is basically just ifs and for loops.” by pdonis on Saturday December 04, 2021 @03:34PM (#29444065)
> Why don't we use what the metal uses, instead of these "expressive abstractions"?

Because the "expressive abstractions" are much easier to reason about and save programmers lots of mental effort. And, as I have commented upthread, ifs and for loops are by no means the only such abstractions.

> because the latter is unfamiliar, it's spoken about in the same manner you present: as if it is some highly abstract, complicating, high-level feature

If expressing your program in the lambda calculus is easy for you to reason about and saves you enough mental effort, go for it. But don't expect your code to be readable or understandable by many other people. The reason why ifs and for loops (and other "expressive abstractions", since as I have said, those are by no means the only ones) are ubiquitous in programs is that they are easy for lots of programmers to reason about. Whereas the lambda calculus is only easy for a very small subset of programmers to reason about.

Re:“Coding is basically just ifs and for loops.” by reikonomusha on Saturday December 04, 2021 @05:01PM (#29444691)
I'm not suggesting people "express programs in the lambda calculus", but instead that incorporating a philosophy of functions and their composition is not at all a bizarre concept. Loops and ifs work miserably with any hierarchical data, compared to recursion, for example. A lot of the world's data is hierarchical.

We now have a chicken-egg problem. I can freely admit that for+if is easy for programmers to understand solely because of how we are educated, and not due to any Bruce Lee hocus pocus about simplicity or fundamentalism, as so many others here suggest.

A programmer who, say, learned from SICP first would find a for loop awkward and bizarre when you could "just" tail-recurse.

Re:“Coding is basically just ifs and for loops.” by pdonis on Saturday December 04, 2021 @11:36PM (#29446718)
> incorporating a philosophy of functions and their composition is not at all a bizarre concept

Sure, functions and their composition are very often another highly useful abstraction that is easy to reason about and saves the programmer a lot of mental effort.

> We now have a chicken-egg problem.

No, just a recognition, which was not there in the original claim, that ifs and for loops are not the only useful abstractions.

> A programmer who, say, learned from SICP first would find a for loop awkward and bizarre when you could "just" tail-recurse.

Perhaps, but I think such a programmer who needed his code to be readable and understandable by a lot of other people in a large project would end up inventing a "for-loop" macro or something similar that, while it might use tail recursion under the hood, would express the construct in a way that programmers could understand regardless of how they learned programming.

Re:“Coding is basically just ifs and for loops.” by mbot5324 on Saturday December 04, 2021 @02:12PM (#29443452)
> as if it is some highly abstract, complicating, high-level feature

But symbol calculus is a highly abstract, complicating, high-level system assembled out more reality-based systems beneath it. If it seems simple to you, you're just under the curse of knowledge.

Re:“Coding is basically just ifs and for loops.” by reikonomusha on Saturday December 04, 2021 @02:16PM (#29443485)
I'm not sure what a "symbol calculus" is. Do you mean "lambda calculus"? I think that's a lot less complicated and abstract than a fabled machine with an infinite tape that's controlled by a transition graph of symbolic states. :)

And I don't know what a "reality-based system" is.

Re:“Coding is basically just ifs and for loops.” by xyzzy_plugh on Saturday December 04, 2021 @02:21PM (#29443532)
You're confusing computer science with writing software to run on hardware. Coding requires the latter, but not the former.
Re:“Coding is basically just ifs and for loops.” by reikonomusha on Saturday December 04, 2021 @02:29PM (#29443589)
Oof, and to think one could helpfully inform the other! :) To be clear, I am a programmer, not a computer scientist, so my opinions are based off writing code and managing teams to write code that works, and less so about abstract machinations of computer scientific thinking.
Re:“Coding is basically just ifs and for loops.” by AmpsterMan on Saturday December 04, 2021 @07:58PM (#29445811)
For the record, I generally think that people exaggerate the complexity of Functional styles.

I think the reason that stateful, imperative code is the default is because that is how we tend to "think". Example, if I wanted to get a list of items for the grocery store, I get a piece of paper (instantiate an array), go through the list of things I might need (loop through a source array) and write down the ones I definitely need (append onto the destination array). If I run out of space, I get a new piece of paper and continue the process.

With that algorithm, I can stop and test each individual statement; I don't need to "think about it" because I can write and execute a tiny part of it (even if I'm only executing it in my mind).

In a functional style, I have to think more declaratively. Given all my items, filter out the ones that need replacing and give me that list. It's much easier to reason about abstractly, but I have no details about w how that's actually happening.

I think this kind of thinking is superior most of the time: I would rather read map.filter.reduce more than a for loop with branch statements any day of the week, but I am trusting the implementations of the mapping and filtering and reducing functions. Of course, for any non-trivial algorithm one is still passing a function into the map/filter/reduce anyway so I can still reason about those smaller stateful sections without worrying about the map/filter/reduce piping.

Perhaps I've never worked in a truly pure functional style so I may not be dealing with the mountains of abstractions others seem to complain about

Re:“Coding is basically just ifs and for loops.” by kaba0 on Saturday December 04, 2021 @06:06PM (#29445140)
Which without side effects can be very heavily optimized (probably even better) than imperative code? Hell, the pipelining inside GPUs, and CPUs are perhaps closer to lambda calculus than Turing machines.

It’s not like the machine code will look much closer to your C code either. That’s also a spell of “compiler writers and hardware vendors trying to uphold the view that C programmers are so close to hardware and that memory access is flat”.

Re:“Coding is basically just ifs and for loops.” by jacoblambda on Saturday December 04, 2021 @02:19PM (#29443507)
Personally I disagree. We should be using state machines and pure functions. If+for loops are just what's easiest to express in the major languages of today. they are no more or less computationally expensive but due to lack of tooling they are often cheaper to write.

In languages and libraries that allow FSM and pure functional kernel based designs you can get just as clear logic that is expressible not just to the programmer but also to business personnel. It's counter-intuitive to a certain extent because so much of programming is built around imperative programming but FSM based logic is and will continue to be easier to understand long term because you can trivially visualise it graphically. This ultimately is what a lot of the functional paradigm is built around. Use the mathematical and graphical representations we've used to understand systems for decades. They are well understood and most people can understand them with little to no additional education past what they learned in their business or engineering bachelors degrees.

Re:“Coding is basically just ifs and for loops.” by kbenson on Saturday December 04, 2021 @03:35PM (#29444072)
In a very real way, it's all conditional jumps in assembly, and every thing you've learned to make programming easier by allowing more directly letting you express your high level intent is just sugar. It might even help some or most of the time. But what you're actually doing is creating a bunch of branches and loops, and as much as the high level stuff might help, you really shouldn't forget this is the medium you actually work in.

Most professions have a healthy respect for the base materials they work with no matter how high the abstractions and structures they build with it go. Artists know their paints, stone, metal, etc. Engineers know their melaterials as well. They build by taking the advantages of each material into consideration, not assuming that it's no longer relevant to their job because they get to just work in I-beams. Programmers would do well to adopt a healthy respect for their base materials, and it seems like often we don't.

Re:“Coding is basically just ifs and for loops.” by Vetch on Saturday December 04, 2021 @05:04PM (#29444708)
> high level intent is just sugar

I disagree with how your use of "just" here. It's common for programmers to dismiss the importance of syntax but syntax and notation are the interface and UX between the language semantics and your brain. It's no less important to get this right. There's a half-joke that Europe was able to rapidly advance in Calculus beyond Britain due to the superiority of Leibniz notation.

> healthy respect for their base materials

What's unique about computers is the theoretical guarantee that the base does not matter. Whether by lambda calculus, register machines or swarms of soldier crabs running from birds in specially designed enclosures, we're fine as long as we appropriately encode our instructions.

> bunch of branches and loops

You could also easily say it's just a bunch of state machines. We outsource tedious complexity and fine details to compiler abstractions. They track things for us that have analogues in logical deduction so that as long we follow their restrictions, we get a few guarantees. When say, writing asynchronous non-deterministic distributed programs, you'll need all the help you can get.

Even designing close to the machine (which most programs will not need) by paying attention to cache use, memory layout, branch divergence or using SIMD remain within the realm of abstractions.

Re:“Coding is basically just ifs and for loops.” by mise_en_place on Saturday December 04, 2021 @03:50PM (#29444208)
Agree with this a lot. In other words, don’t be too clever. That leads to an unmaintainable codebase. There is value in simplicity and not overly using abstractions that take you farther and farther away from bare metal.
Re:“Coding is basically just ifs and for loops.” by kinjba11 on Saturday December 04, 2021 @06:52PM (#29445426)
> There is value in simplicity and not overly using abstractions that take you farther and farther away from bare metal.

This is a contradiction. Simplicity is obtained through abstractions. As an example, fifty years ago, 'goto' reigned supreme. Then structured 'if/else/for' took over, as the superior abstraction over 'goto'. Now use of 'goto', while being far simpler to implement and closer to the bare metal, is commonly derided by many programmers.

The long term trend in software is constantly increasing abstraction hiding mountains of complexity, which increases both simplicity and complexity. Writing print('hello world') is simple, but the compiler, OS, silicon, etc. that makes that simplicity possible is extremely complex.

Re:“Coding is basically just ifs and for loops.” by kaba0 on Saturday December 04, 2021 @05:55PM (#29445063)
Programming is primarily about managing complexity. Other than perhaps mathematics, there is no other field that must, should and can apply the amount of abstraction on top of abstraction as software engineers do.

It is a must, because decades of business requirement built on top each other without understanding the whole is complex. Writing a JIT-compiler that can routinely change between interpreting code and executing it natively, a database optimizing queries, a mathematical library using some fancy algorithm are all complex, in a way that is not reducible.

Complexity easily outgrowth even the whole of our mathematics, we can’t prove any non-trivial property of a program, halting problem, etc.

So all in all, no, we can only respect our “base materials” by finding the proper abstraction for the problem, as our base material is complexity itself. It might be for loops and ifs, but it very well be a DSL built on top of who knows how many layers, because at that abstraction level can we even start to map the problem domain to human consumable ideas.

Re:“Coding is basically just ifs and for loops.” by marginalia_nu on Saturday December 04, 2021 @02:31PM (#29443605)
> Personally I disagree. We should be using state machines and pure functions. If+for loops are just what's easiest to express in the major languages of today. they are no more or less computationally expensive but due to lack of tooling they are often cheaper to write.

In my experience programming programming with primitives and basic flow control operations frequently tends to be at least be order of magnitude faster than more complex state management paradigms. Compilers are very good at optimizing that style of code. Loops often get unrolled, the and the branch predictor is kept happy. A good compiler may use vector expressions.

In many cases with cold code it flat out doesn't matter, the CPU is plenty fast, but when it does matter, explicit if-and-for code absolutely mops the floor with the alternatives.

Re:“Coding is basically just ifs and for loops.” by kaba0 on Saturday December 04, 2021 @06:00PM (#29445092)
Will your manually written imperative code beat an SQL database for the same task? Because it uses a very very high level description on what it has to do and chooses an appropriate algorithm for that for you.

You can optimize one specific query (quite painstakingly, I believe) to beat a general db, but it is very far from clear that “for loops will beat higher level abstractions”, imo.

Re:“Coding is basically just ifs and for loops.” by marginalia_nu on Saturday December 04, 2021 @06:23PM (#29445246)
In designing my search engine, I ended up building a custom index instead of using an off-the-shelf database solution. Franky it's so much data a SQL database can't even load it when run on the same server that runs my entire search engine.

With my own set-up I can have my data in pre-calculated immutable tables that are memory mapped off disk. That means I can write lock-free code. My updates are large hour-long batch operations off a written journal.

For the lexicon I'm also rolling a special one-way compression scheme/hash function that guarantees uniqueness but only works due to quirks with the data.

General purpose databases can't do these things, because then they wouldn't be general purpose databases.

SQL databases perform really well on average given your query is relatively optimized, but they do not represent the pinnacle of performance. Any time you want the fastest most efficient code to deal with a particular use case, it pays enormous dividends to roll your own implementation that has domain awareness. It means you can cut corners general solutions simply can't.

Re:“Coding is basically just ifs and for loops.” by jatone on Saturday December 04, 2021 @03:51PM (#29444215)
for loop goes brrrrrrrrrrrrrrrrrrr!
Re:“Coding is basically just ifs and for loops.” by jacoblambda on Saturday December 04, 2021 @05:29PM (#29444894)
At least in the C++ space, stuff like boost-sml is able to produce assembly that is often as fast or occasionally faster than handwritten if or switch based FSM logic.
Re:“Coding is basically just ifs and for loops.” by wruza on Saturday December 04, 2021 @03:08PM (#29443864)
FSM and pure functional kernel based designs you can get just as clear logic that is expressible not just to the programmer but also to business personnel

I’m yet to see a secretary who could “return a new table state such that as if documents became a right fold as binding together a map of composition of signing and copy routines over documents” instead of “get these documents from the table, copy, sign and put them back in a binder”. This is a nonsense some of us want to believe in, but it is not true.

Re:“Coding is basically just ifs and for loops.” by opportune on Saturday December 04, 2021 @03:23PM (#29443975)
I inherited a piece of code that was designed as a state machine and the state machine design basically made the project become pure technical debt as requirements increased over time and engineers had to make it work with the state machine model that had been chosen when the project started.

If the project had instead been designed to have less unnecessary state and “transitions” it would have been a lot easier to make changes.

All those ideas sound good by themselves but they are really bad for “defensive” coding. Good luck selling a project to refactor something when it’s going to take multiple people-years. Once you’ve made the mistake of committing to an inflexible design it’s either that, replace/ignore the thing, or deal with low productivity as long as the thing exists.

Re:“Coding is basically just ifs and for loops.” by astrange on Sunday December 05, 2021 @03:38AM (#29447762)
State machines are refactorable if you use state charts. Using one giant FSM is like committing compiled code.
Re:“Coding is basically just ifs and for loops.” by mro_name on Saturday December 04, 2021 @04:33PM (#29444507)
> state machine model that had been chosen when the project started.

so was the chosen model the issue or choosing a state machine model at all?

Re:“Coding is basically just ifs and for loops.” by FpUser on Saturday December 04, 2021 @03:58PM (#29444255)
I've written many SM implementation starting from one used in low protocols and up to business process middleware so I have an experience and know how incredibly useful and powerful those are when used in right place. But to use them everywhere especially in some math algos would be an insanity worse than GoTo.
Re:“Coding is basically just ifs and for loops.” by usrbinbash on Saturday December 04, 2021 @07:45PM (#29445734)
>They are well understood and most people can understand them with little to no additional education past what they learned in their business or engineering bachelors degrees.

Imperative code:

    Take A and B.
    Add C ml of Water.
    Stir for 2 minutes.
    If it thickened, add D grams of flour, else go back to stiring.
This is easily understood by everyone, degree or no. Once someone figures out loops and the difference between statement and expression, they can essentially understand imperative code.
Re:“Coding is basically just ifs and for loops.” by davidkpiano on Sunday December 05, 2021 @08:50AM (#29449251)
Okay, now put boxes around each sentence and connect them with arrows. ;-)

Imperative code quickly devolves to a point where it is no longer understandable by anyone but the developers who wrote it.

Re:“Coding is basically just ifs and for loops.” by pdonis on Saturday December 04, 2021 @03:31PM (#29444038)
> We should be using state machines and pure functions.

For problems where those are the right tools, sure. But they aren't the right tools for all problems any more than ifs and for loops are.

Re:“Coding is basically just ifs and for loops.” by marginalia_nu on Saturday December 04, 2021 @05:00PM (#29444681)
I've always felt like explicit state machines are the sledge hammer you break out when you can't find any good abstraction to encapsulate the logic. As an intermediate step for parsers it's pretty powerful, but it's not something I want in my hand written code if I have any alternatives.
Re:“Coding is basically just ifs and for loops.” by mro_name on Saturday December 04, 2021 @04:30PM (#29444492)
do you know some nice examples of medium complexity that you can show for inspiration?
Re:“Coding is basically just ifs and for loops.” by pdonis on Saturday December 04, 2021 @03:29PM (#29444027)
> Saying it is all ifs and for-loops is completely true. Everything else, all the abstractions and high level features, are just sugar.

You could just as well say that ifs and for loops are just sugar for gotos and all programming is just gotos.

The reason ifs and for loops are used instead of gotos is that they are very useful abstractions that are easy to reason about and save the programmer lots of mental effort. But they are not the only such abstractions.

To the extent that other abstractions can create problems, it's not because they're really just sugar for ifs and for loops, it's because they are not well crafted abstractions so they are not easy to reason about and don't really save the programmer any mental effort. But there are plenty of abstractions other than ifs and for loops that are well crafted and do save the programmer mental effort, in many cases lots of it.

Re:“Coding is basically just ifs and for loops.” by reikonomusha on Saturday December 04, 2021 @09:50PM (#29446326)
I completely agree with this. A lot of people use the term "too much abstraction" when they mean "bad" or "ineffectual abstraction." For-loops can be a wonderful abstraction, but they're certainly no basis for all abstractions.
Re:“Coding is basically just ifs and for loops.” by CTmystery on Saturday December 04, 2021 @10:25PM (#29446453)
> After enough experience you realize that expressivity and convenience are antipatterns and don't actually simplify things but are harbingers of complexity, bugs, tech debt, even the downfall of organizations and products.

Suggesting that experience leads to jettisoning expressivity is at odds with my direct observations of experienced software engineers working in large teams. The more experience, the _better_ the engineer gets at picking the right level of abstraction to write code that can be maintained by others. Picking a single point on the abstraction spectrum (just above goto but not below it!) is far too rigid for the diversity of tasks that software engineers need to solve.

[dead]
Re:“Coding is basically just ifs and for loops.” by Jensson on Saturday December 04, 2021 @11:11PM (#29446624)
Math today does a lot of things you couldn't do with math back then. It isn't just syntactic sugar, there were simply lots of problems they didn't know how to solve since the math they had wasn't powerful enough to solve it. Calculus for example solved a lot of problems they have, and calculus isn't syntactic sugar for anything, it is a new instruction set.

However the code abstractions people used 50 years ago could still implement all programs we have today. We added a lot of sugar on top, but the core of coding remained the same. For example, you could implement Map, Reduce etc in C, they are just functions and not novel features of programming.

Re:“Coding is basically just ifs and for loops.” by 8ytecoder on Saturday December 04, 2021 @01:51PM (#29443272)
It’s just so sad that the lowest common denominator has become the standard now. When I first learnt Clojure it entirely changed the way I think and solve problems. The code really was elegant.

Obviously, it can only be read by someone who can also understand programming beyond ifs and fors. That’s a non-starter in most environments - enterprise or otherwise.

Funny enough, I see most innovations coming from consultants who do the same work for multiple companies and realise the repeating patterns and extract an abstraction.

Re:“Coding is basically just ifs and for loops.” by sharken on Saturday December 04, 2021 @02:22PM (#29443536)
Ifs and fors are the easiest concepts to explain to non-developers, so it makes sense to start there.

I wouldn't say that they are the standard now, but using and mastering all features in a language is hard.

Add to that design patterns, classes and code layout it becomes a full-time job to keep up.

I have been in contact with code most of my professional life, but still isn't comfortable writing large amounts of code. The simple reason is that i don't do it full-time.

Here are the features in C# just to illustrate how complex a programming language is.

https://www.c-sharpcorner.com/article/c-sharp-versions/

Re:“Coding is basically just ifs and for loops.” by qsort on Saturday December 04, 2021 @03:01PM (#29443812)
I agree that modern software development for non-full time developers is brutal, several of my data scientist colleagues are remarkably brilliant people and yet they struggle with some more advanced programming concepts.

However, most of those features are relatively standard and are more conceptual than syntactical in nature. Bashing people because they don't know stuff is stupid and counterproductive, but I shouldn't be forced to code in the programming equivalent of roman numerals just because someone else can't be properly fucked to understand lambdas or interfaces or generics, all stuff that's literally covered in your run-of-the-mill CS 101 course.

It all boils down to having enough humility and empathy to understand that other people are not, in fact, the same as us.

Re:“Coding is basically just ifs and for loops.” by 8ytecoder on Saturday December 04, 2021 @03:19PM (#29443946)
That’s what I mean. Each language has a different syntax and it takes a while to gain mastery over it and that’s fine. But there are concepts that are immediately portable to multiple language.
Re:“Coding is basically just ifs and for loops.” by tonyedgecombe on Sunday December 05, 2021 @04:27AM (#29447946)
C# was good enough for me at version 4.0. I use many of the newer features but they seem to be well into the law of diminishing returns now.
Re:“Coding is basically just ifs and for loops.” by usrbinbash on Saturday December 04, 2021 @02:01PM (#29443365)
>I have no beef with if+for, but a large part of the reason they're "goto tools", if you will, is because industry is slow to assimilate many state-of-the-art ideas, sometimes by as much as 40 years.

For assimilation to happen, the state-of-the-art solution also has to result in a net gain over the existing solution, and the higher the differential in complexity between the two, the bigger that gain has to be.

Re:“Coding is basically just ifs and for loops.” by gopher_space on Saturday December 04, 2021 @02:42PM (#29443690)
Functionally, this looks like selling off your client base and closing the doors rather than rewriting internal tools that mostly still work.

There's no "rubber meets the road" in OPs position because there's no cost in their calculations.

Re:“Coding is basically just ifs and for loops.” by reikonomusha on Saturday December 04, 2021 @02:02PM (#29443373)
And, these days, "net gain" in an industrial context is typically tied to almost no aspect of the quality of the code, but more to the management of large groups of people, as well as stability and growth of the business.
Re:“Coding is basically just ifs and for loops.” by enneff on Saturday December 04, 2021 @03:15PM (#29443915)
What this really means that once you get to a certain level of experience and seniority the actual code you write in the small is pretty much irrelevant. What matters is the overall architecture of what you’re building: the data structures and APIs. The challenge becomes about working together as a team, and with other teams within your ecosystem. Sophisticated language constructs don’t actually help you solve those problems, and imo their benefit is marginal where they do help.
Re:“Coding is basically just ifs and for loops.” by filoeleven on Saturday December 04, 2021 @08:16PM (#29445916)
I view map/filter as better abstractions than for loops, and do not consider them to be sophisticated language constructs. They correlate with descriptions of a program’s goals much more naturally than for loops do: get the name of each user, remove everyone under 21, only show accounts with positive balances, etc. Reduce is more arguable, but I think it also applies: show the total amount of money in all of this user’s accounts.

“If” however seems pretty fundamental.

Re:“Coding is basically just ifs and for loops.” by drugones on Saturday December 04, 2021 @04:01PM (#29444275)
This!

With at additional level of abstraction you could say “goto jumps”, but “if and loops” gives an commonly understandable logic for everyone; deeper abstractions increase reading complexities, while higher abstraction is achieved via functions and overall architecture.

Scaling up those “if and loops” is the challenge as a team or a single, with the common goals being to keep the software under control.

Re:“Coding is basically just ifs and for loops.” by nerdponx on Saturday December 04, 2021 @01:55PM (#29443305)
Meh, most business logic really is "if" and "foreach". That doesn't mean it's not complicated, as you say. But all that category theory stuff, at the end of the day, really is just an attempt to manage the complexity of lots of conditional branching and iteration.
Re:“Coding is basically just ifs and for loops.” by loopz on Sunday December 05, 2021 @11:00AM (#29450198)
If and loop aren't mathematical in the same sense as set theory and set operations are.
Re:“Coding is basically just ifs and for loops.” by Sharlin on Saturday December 04, 2021 @01:56PM (#29443311)
> they're "goto tools"

I see what you did there.

Re:“Coding is basically just ifs and for loops.” by engineeringwoke on Saturday December 04, 2021 @01:49PM (#29443250)
> debugging hairy, nested, imperative conditionals with for-loops that are off-by-1

Isn't this just a complicated case of ifs and fors?

Re:“Coding is basically just ifs and for loops.” by reikonomusha on Saturday December 04, 2021 @01:53PM (#29443285)
Sure, but the word "just" is doing a lot of work. It seems to be where a code base of uncomplicated ifs and fors leads to asymptotically, because both of those constructs don't prohibit you in any way from sneaking in "just another line" to either of them.
Re:“Coding is basically just ifs and for loops.” by rsj_hn on Saturday December 04, 2021 @03:21PM (#29443960)
There are a lot of sophisticated problems dealing with enterprise software even in higher languages and even in situations where things like performance or resource usage is not a primary concern.

For example, how do you handle authorization, logging, and how do you make the code maintainable? That's a really tough problem that requires a lot of thought about the overall system design.

And of course it's always a lie to say that performance and resource usage aren't a concern -- they're not a concern until they are.

Re:“Coding is basically just ifs and for loops.” by phendrenad2 on Saturday December 04, 2021 @03:14PM (#29443905)
> is because industry is slow to assimilate many state-of-the-art ideas, sometimes by as much as 40 years

How convenient that the software industry is about 40 years old. So these ideas should "break through" this invisible arbitrary corporate waiting area into the limelight any day now, right?

Re:“Coding is basically just ifs and for loops.” by reikonomusha on Saturday December 04, 2021 @05:07PM (#29444730)
They are breaking though. For instance, Python just got (a very limited form of) pattern matching. It has been A Good Idea since at least the 1970s. Garbage collection has been known since the 1950s but only became "mainstream" in Java.
Re:“Coding is basically just ifs and for loops.” by perl4ever on Saturday December 04, 2021 @04:17PM (#29444398)
The significance of off-by-one errors depends on whether you predictably get a runtime error on the first execution, or not.
Re:“Coding is basically just ifs and for loops.” by jstx1 on Saturday December 04, 2021 @01:55PM (#29443307)
- it's okay to use printing instead of a debugger

- you don't need to write classes for everything

- it's okay to write something in a more verbose way to make it clear for other people

- your tools don't need to be perfect to get things done

I need more of these, maybe some that aren't as reductionist as Carmacks's original post.

Re:“Coding is basically just ifs and for loops.” by mjevans on Saturday December 04, 2021 @04:21PM (#29444440)
The really useful 'print' debug lines might be kept at additional 'debug' flag levels. This is particularly useful for tracing the behavior of programs that no longer have debug symbols and are running in real environments.
Re:“Coding is basically just ifs and for loops.” by vlunkr on Saturday December 04, 2021 @04:40PM (#29444549)
This post by Aaron Patterson made me realize it's fine to debug with print statements

https://tenderlovemaking.com/2016/02/05/i-am-a-puts-debugger...

In rare cases I pull out a real debugger, but most of the time the right prints in the right places are just as good. I can also iterate much faster because I'm not jumping between the code the the debugger, or pulling the debugger out of the loop it's stuck in.

Re:“Coding is basically just ifs and for loops.” by therealjumbo on Sunday December 05, 2021 @03:32PM (#29452895)
I've come to the conclusion that it's a good skill to have since it's (or logging which is basically the same) the only debugging method that's always guaranteed to be available. For example there's lots of build and CI tools out there that have no Real Debugger.
Re:“Coding is basically just ifs and for loops.” by gdulli on Saturday December 04, 2021 @02:01PM (#29443358)
I'd never seen that meme before, but there's a Bruce Lee quote (maybe apocryphal) that has had a lot of meaning for me ever since I got over the same hump myself.

“Before I learned the art, a punch was just a punch, and a kick, just a kick. After I learned the art, a punch was no longer a punch, a kick, no longer a kick. Now that I understand the art, a punch is just a punch and a kick is just a kick.”

Re:“Coding is basically just ifs and for loops.” by jareklupinski on Saturday December 04, 2021 @02:09PM (#29443434)
makes me think of the Buddhist "Before enlightenment: chop wood, carry water. After enlightenment: chop wood, carry water".

not my favorite source since it doesn't go into the 'scaling the mountain' bit, but every source that talks abt that part seems to be...eh: https://buddhism.stackexchange.com/questions/15921/what-is-t...

Re:“Coding is basically just ifs and for loops.” by lanstin on Saturday December 04, 2021 @04:33PM (#29444506)
I always took that to mean something like this:

Q: What is the difference between an enlightened person and an ordinary person?

A: There is no difference, but only the enlightened person knows this.

Re:“Coding is basically just ifs and for loops.” by kwertyoowiyop on Saturday December 04, 2021 @02:46PM (#29443715)
“Before enlightenment: if then. After enlightenment: if then.”
Re:“Coding is basically just ifs and for loops.” by anon9001 on Saturday December 04, 2021 @04:10PM (#29444340)
Before agile: it's not done yet

After agile: it's not done yet

Re:“Coding is basically just ifs and for loops.” by Jensson on Saturday December 04, 2021 @11:23PM (#29446665)
After agile: it's not done
Re:“Coding is basically just ifs and for loops.” by montalbano on Saturday December 04, 2021 @02:25PM (#29443556)
Funny, I posted this on another HN thread [0] recently, but it's perfectly relevant again:

We shall not cease from exploration

And the end of all our exploring

Will be to arrive where we started

And know the place for the first time.

T. S. Eliot - Little Gidding

[0] https://news.ycombinator.com/item?id=29043941

Re:“Coding is basically just ifs and for loops.” by dharmab on Saturday December 04, 2021 @02:31PM (#29443602)
How then am I so different from the first men through this way?

Like them, I left a settled life, I threw it all away

To seek a Northwest Passage at the call of many men

To find there but the road back home again

Stan Rogers, "Northwest Passage"

Re:“Coding is basically just ifs and for loops.” by kwertyoowiyop on Saturday December 04, 2021 @02:46PM (#29443720)
Sounds good. I still remember my BASIC.
Re:“Coding is basically just ifs and for loops.” by cs702 on Saturday December 04, 2021 @01:35PM (#29443112)
That image[a] is so funny because it is so true:

Anyone who has ever written any software has felt like the unenlighted half-person in the middle of that distribution at least once -- for example, when learning how to code with a different approach in a new language.

I have felt like that more than once. Everyone here has, I suspect.

--

[a] https://twitter.com/nice_byte/status/1466940940229046273/pho...

Re:“Coding is basically just ifs and for loops.” by tester756 on Saturday December 04, 2021 @05:29PM (#29444896)
I'm may be biased because I spent too much time arguing about this

but you hear those $fancy_principles / fp / hard oop / "clean code" evangelists, and then you go to any repo of real world software - linux, compilers, kubernetes, git, blablabla and everywhere you see for loops, goto, ladders of if statements

Re:“Coding is basically just ifs and for loops.” by kaba0 on Saturday December 04, 2021 @05:43PM (#29444986)
I mean, you cherry-picked by quite a criteria there. It’s all C and Go, and they somewhat lack higher level abstraction capabilities. On the other hand compilers are often written in C++, or are bootstrapped in the very same language though. Also, what about OpenJDK, elastic search, all the web servers running the whole cloud? Linux might be the underlying OS, but that’s not the program actually doing business logic. If anything, it’s just another layer of abstraction.

Also, let’s be honest, C does all these “virtual method” magic on a per-project basis which will not be understood by any tool ever (all those function pointers to whole new implementations passed from God knows who, with barely any typing). At least FP and OOP knowledge somewhat transfers and is queryable by tools.

Re:“Coding is basically just ifs and for loops.” by tester756 on Saturday December 04, 2021 @06:13PM (#29445182)
Ok, another example: C# Compiler, .NET internals/std/yadayada, same stuff.

My claim is:

Almost all real world, OSS, big, battle-proven code bases are nowhere even close to evangelist's "sanity".

They're full of loops, nulls, gotos, ifs and all ""bad stuff""

>all the web servers running the whole cloud

I literally opened first file that I've seen in nginx repo and take a look at this:

shitton of ifs, for loops gotos and all of that in one, a few hundreds lines long method.

https://github.com/nginx/nginx/blob/master/src/http/ngx_http...

>On the other hand compilers are often written in C++

are they?

>or are bootstrapped in the very same language though.

thus what?

Re:“Coding is basically just ifs and for loops.” by kubb on Saturday December 04, 2021 @01:52PM (#29443279)
I gravitate towards useful abstraction. I've written the same loops (find an element, find a maximum, do something to every element, filter elements, etc.) 10 000s of times by now. It got old after the first 100.
Re:“Coding is basically just ifs and for loops.” by bsder on Saturday December 04, 2021 @02:36PM (#29443649)
The more experience you have, the more you see through the code to what is underneath.

"...there's way too much information to decode the Matrix. You get used to it, though. Your brain does the translating. I don't even see the code."

Re:“Coding is basically just ifs and for loops.” by bmitc on Saturday December 04, 2021 @05:11PM (#29444761)
This is basically the progression in any field or craft. As one becomes more experienced, one basically figures out the optimized stuff needed to successfully solve the problem in hand, successful in the sense that it both meets current requirements and enables future changes or evolution.

I describe this path of discovery as:

beginner: function over form

intermediate: form over function

transcendence: form is function

However, I will disagree that coding is just about ifs and for loops. To me, coding, programming, software development, or whatever you want to call it is about three things: how to use a computer to do something, communication between people (including your future self), and how to think about a domain. “ifs and for loops” does not capture this.

Re:“Coding is basically just ifs and for loops.” by thewarrior on Saturday December 04, 2021 @01:43PM (#29443194)
Except it never can be that simple because many systems have millions of ifs when the entire system is considered. So architecture and parallel evolution of those millions of ifs becomes an entire field of study :)
Re:“Coding is basically just ifs and for loops.” by feoren on Saturday December 04, 2021 @09:17PM (#29446185)
The problem with this is that most software is absolute garbage and most code is an awful, unmaintainable mess. The middle of that curve are all the people who are trying to improve that situation. The right side of the curve are the people who have given up. But maybe that does make them the smarter ones.
Re:“Coding is basically just ifs and for loops.” by throw10920 on Saturday December 04, 2021 @04:18PM (#29444410)
Do you write your code in notepad or pico, or use brainfuck as your primary programming language, or copy your code to a new folder for version control? Those things are all the simplest in their tool category.