Live data from Hacker News

“Coding is basically just ifs and for loops.”

twitter.com

381–390 of 418 posts

Re: “Coding is basically just ifs and for loops.”

#381

Earlier quoted context omitted.

That’s what disappoints me in modern Java. There is practically no ifs. It makes it inaccessible to beginners on the project, and the streams are about twice as slow… just because devs think they are more clever if they pile 7 “.map()” to transform a list. list.stream().filter(Objects::nonNull).map(User::getUsername).filter(Objects::nonNull).filter(name -> name.contains(searchString)).map(name -> “We have found your…

the two snippets you posted do different things 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 m…

The snippets actually do the same thing, as long as you add a .findFirst() to the first example to make it valid Java code.

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...

Re: “Coding is basically just ifs and for loops.”

#382

"First a punch is just a punch, Then a punch is not only a punch, And finally a punch is just a punch" (heard from Bruce Lee) 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…

That’s what disappoints me in modern Java. There is practically no ifs. It makes it inaccessible to beginners on the project, and the streams are about twice as slow… just because devs think they are more clever if they pile 7 “.map()” to transform a list. list.stream().filter(Objects::nonNull).map(User::getUsername).filter(Objects::nonNull).filter(name -> name.contains(searchString)).map(name -> “We have found your…

I just started using Java's functional side a few weeks ago. Lambdas are really nice and often make the code clearer. I like writing more declaratively.

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.

Re: “Coding is basically just ifs and for loops.”

#384

Earlier quoted context omitted.

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…

>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…

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.”

#385

Then what the fuck is a monad?!? Seriously I still don’t know what a monad is and apparently it’s just a bunch ifs and for loops, so I guess I’m pretty stupid.

A monad is just a monoid in the category of endofunctors... duh!

It's not "the" monoid in the category of endofunctors though, just "a" monoid. That also describes Applicative (less powerful) and Arrow (more powerful).

Re: “Coding is basically just ifs and for loops.”

#386
post #357
post #312

Earlier quoted context omitted.

They’re obsolete now, except on YouTube.

ICE has thousands of uses, they aren't just for cars. 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…

> 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.

Re: “Coding is basically just ifs and for loops.”

#387

"First a punch is just a punch, Then a punch is not only a punch, And finally a punch is just a punch" (heard from Bruce Lee) 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…

As with so many other things, through mastery and practice of the “right ways” you will often discover flaws in them and that is when that which you are practicing begins to become a true art form.

Re: “Coding is basically just ifs and for loops.”

#388

"First a punch is just a punch, Then a punch is not only a punch, And finally a punch is just a punch" (heard from Bruce Lee) 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…

I started off writing a lot of 68000 machine code. I was always amazed what you could accomplish with a lot of loops and branches. I never lost that sense that at whatever higher level I was at later on, it was all loops and branches.

It’s not about how many loops you have; it’s about what you put in them and how deep.

Re: “Coding is basically just ifs and for loops.”

#389
post #312

Earlier quoted context omitted.

Yes, it's a good talk. Think of all the extremely talented internal combustion engine engineers that will be obsolete in 20 - 30 years.

They’re obsolete now, except on YouTube.

Hydrogen fuel isn't going away.

Re: “Coding is basically just ifs and for loops.”

#390
post #357

Earlier quoted context omitted.

ICE has thousands of uses, they aren't just for cars. 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…

> 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 r…

What is more green? Coal or natural gas plants, AC lines that lose some power, building transformers, using AC to DC converters for all our power supplies, refining rare earth minerals to make decaying chemical cells, and using brushless motors (I think?) versus oil drilling with huge machines, refineries, transport and risks of oil spills, and building combustion engines? ICE looks like it can be way more efficient.
Post reply on HN