Sunday, September 15, 2024

whalefall!

Are you familiar with Whale Fall?

Here's a cool description from tumblr:
"With a "normal" whalefall, we're talking about something (a dead whale, to be precise) that lands in an EXTREMELY nutrient-poor environment, the deep ocean. It's not the equivalent of "a truck full of free hamburgers lands from the sky in the middle of your neighbourhood". This is an environment where an important part of the food chain is "marine snow", aka flakes of organic matter (including feces) that drift down from above, and they eat that because it's possible to get nutrients from it. So when a whole-ass (or partial-ass, because it's already been nibbled on from sharks and the like) whale carcass arrives, it is something MAJOR. It starts a whole new localized ecosystem, an oasis of life; those that eat the dead whale, those that eat those that eat the dead whale, and so on. And as the whale is consumed, the creatures there shift, leaving when there's nothing left that they'd eat, arriving when parts of the whale that they DO eat are now exposed, and it continues until the very bones have been devoured.
Whalefalls are fascinating."
The tumblr post goes on to think about a "Sky Whale Fall", the death of a celestial being that changed the magic / cryptid ecosystem in an eldritch horror kind of way.
But, here's a less fun play on the idea - some industries are going through some serious, serious party-over-hangovers - tech and other startups after the thrill of COVID-era zero interest rates, the film industry once the streaming bonanza started running out of steam... but maybe more worrisome, what if the entire introduction of the Internet was similar?
"The invention of the internet is like a whale carcass at the bottom of the ocean. It's an anomaly that lasted 50 years. A lifetimes-long anomaly. Long enough that people started and ended their career within its duration. Long enough that books about "business practice" were written by people who thought it was a new normal. When tech VCs try to apply their startup culture to biotech, scientists have to slowly explain to them that you cannot launch a crop alpha release in 18 months"
Sobering metaphor. Especially for a guy who started his career as the whale was just hitting the seafloor, and just got laid off again.

Friday, September 13, 2024

redux, redux: why people like and dislike it

I was doing some debugging earlier this week on frontend heavy with Redux.

For those who don't know, React (or almost any component based UI system) has a problem - how to share information between parent and child (and grandchild and greatgrandchild etc) components.

No right-thinking developer likes to admit it, but sometimes you kind of "need" global variables, or at least some kind of widely shared state - but raw global variables are horrible, you don't know where or what may change the information you're depending on, you have to be careful a child's local variable doesn't share the same name as something from the wider context, etc.

Now "React 101" tells how you can have a component passing data to a direct child via props. And "React 102" explains how to have call backs so the child can set things in the parent. But again, having to explicitly pass across generations as props - from greatgrandparent to grandparent to parent to child is burdensome.

Eventually, when React got Hooks it got Contexts - roughly speaking it's just a nice way of declaring regions for semi-global variables, but its usage is declared pretty explicitly, with useContext() pulling the shared information back into local state.

Before Hooks' introduction 4-5 years ago, Redux was the go-to choice to solve the "global variable" issue Last year's State Of JS is curiously silent about it's current happenings, but its usage and popularity were strong but declining in previous years.

I always thought there was a fair amount to dislike about Redux even when it was the only game in town - it tends to put the code path for a single interaction all over the place - declare an action in one file, have something like a button click dispatch that action in another file, have a reducer take the action and modify the global store in another file, then back in the component use mapStateToProps or a useSelector hook to see and act on the change. 

(This is a somewhat contrived example, since a single UI action should often be handled as local state to a component, but I've definitely seen examples like this in the wild! And in any event, even for stuff making good use of Redux there's still at least 3 files for anything involving this kind of shared action -> state change -> display kind of chain.)

But doing some debugging (I suspect the problem was probably based on data from the endpoints, but I wanted to get a better feel for why a button was being hidden) - I admit Redux's devtools are kind of neat:

You can see the actions on the left, and what the state was at each action's point on the right (plus you can pin a certain tree of the state and see just when it gets modified.) I think there are also tools to time travel to earlier states - which very much embraces the declarative programming paradigm, the idealized world of state goes in, full UI comes out.

You still need to do bread-and-butter debugging (sometimes it might not be clear just which action or reducers are in play) but it is clearly a cool tool to have around.

Another advantage to heavy Redux use is its middleware; if you have most of your site tooled with Redux, you can have, say, analytics middleware that just listens for the relevant action events and record then them - this was one of the approaches we landed on with this project, and was cleaner than having to insert a lot of "onclick" monitors.

Thursday, September 5, 2024

more on pieter levels

Disclaimer: I do have a suspicion that I might not agree with all of Pieter Levels politics. (I think he wants Europe to be run a bit more like the USA, though I'm not convinced that's the best way to a good quality of life for most of us.)

(FOLLOWUP: listening to the whole podcast,. I think he might be a little libertarian/entrepreneurial but not much that seems that egregious politically)

Anyway, I did like this dive into his stack for MVPs.

I'm still curious when if ever he uses CSS toolkits - most of his sites look pretty sharp. So he either has started using something or he just has a very good eye for design, and goes back to a few tricks.

Wednesday, September 4, 2024

pieter levels is a hero of indie web dev

I lightly edited this transcript from Pieter Levels and Lex Friedman on the Lex Fridman podcast:
I'm seeing a revival now. People are getting sick of frameworks. Like all the JavaScript frameworks are so like, what do you call it? Like wieldy, so it takes so much work to just maintain this code and then it updates to a new version. You need to change everything. PHP just stays the same and works.

Yeah, can you actually just speak to that stack? You build all your websites, apps, startups, projects, all of that with mostly vanilla HTML... JavaScript, jQuery, PHP, and SQLite. And so that's a really simple stack, and you get stuff done really fast. Can you just speak to the philosophy behind that?

I think it's accidental, 'cause that's the thing I knew, like I knew PHP, I knew HTML, CSS, 'cause you make websites and when my startups started taking off, I didn't have time to... I remember putting on my to-do list like 'learn Node.js', 'cause it's important to switch, 'cause... This obviously is much better language than PHP, and I never learned it. I never did it, 'cause I didn't have time. These things were growing like this, and I was launching more project and I never had time. It's like one day, I'll start coding properly and I never got to it. -

I sometimes wonder if I need to learn that stuff. It's still to do for me to really learn Node.js or Flask [or] React. It feels like a responsible software engineer should know how to use these, but you can get stuff done SO fast with vanilla versions of stuff.

Yeah, it's like software developers if you wanna get a job and it's like, you know, people making stuff like startups and if you want to be entrepreneur probably maybe shouldn't, right?

I wonder if there's like, I really wanna measure performance and speed. I think there's a deep wisdom in that. I do think that frameworks and just constantly wanting to learn the new thing this complicated way of software engineering gets in the way. I'm not sure what to say about that, because definitely like you shouldn't build everything from just vanilla JavaScript or vanilla C, for example. C++ when you're building systems engineering is like, there's a lot of benefits for pointer safety and all that kind of stuff. So I don't know, but it just feels like you can get so much more stuff done if you don't care about how you do it.

Man, this is my most controversial take, I think, and maybe I'm wrong, but I feel like there's frameworks now that raise money. They raise a LOT of money. They raise 50 million, 100 million, 300 million dollars. And the idea is that you need to make the developers, the new developers, like when you're 18 or 20 years old, right? Get them to use this framework and add a platform to it. Where the framework can... It's open source, but you probably should use the platform which is paid to use it. And the cost of the platforms to host it are a thousand times higher than just hosting it on a simple AWS server or a VPS on DigitalOcean, right? So there's obviously like a monetary incentive here. We wanna get a lot of developers to use this technology and then we need to charge them money 'cause they're gonna use it in startups and then the startups can pay for the bills. It kind of destroys the information out there about learning to code because they pay YouTubers, they pay influencers, developer influencers is a big thing... And same thing what happens with like nutrition and fitness or something. Same thing happens in developing, they pay this influencer to promote this stuff, use it, make stuff with it, make demo products with it. And then a lot of people are like, "Wow, use this." And I started noticing this 'cause when I would ship my stuff, people would ask me, "What are you using?" I would say, "PHP, jQuery, why does it matter?" And people would start kind of attacking me like, "Why are you not using this new technology, this new framework, this new thing?" And I say, "I don't know, 'cause this PHP thing works and I'm not really optimizing for anything, it just works." And I never understood like why, I understand there's new technologies that are better and there should be improvement, but I'm very suspicious of money. Just like lobbying. There's money in this developer framework scene. There's hundreds of millions that goes to ads or influencer or whatever. It can't all go to developers. You don't need so many developers for a framework, and it's open source. To make a lot of more money on these startups.

So that's a really good perspective. But in addition to that is like, when you say better, it's like, can we get some data on the better? Because I wanna know from the individual developer perspective and then from a team of five, team of 10, team of 20 developers... Measure how productive they are in shipping features. How many bugs they create, how many security holes result.

PHP was not good with security for a while, but now it's good.

In theory, in theory- Is it though?

Now it's good.

No, now as you're saying it, I wanna know if that's true because PHP was just the majority of websites on the internet. Is it just overrepresented? Same with WordPress? Yes, there's a reputation that WordPress has a gigantic number of security holes. I don't know if that's true. I know it gets attacked a lot because it's so popular. It definitely does have security holes, but maybe a lot of other systems have security holes as well. Anyway, I just sort of questioning the conventional wisdom that keeps wanting to push software engineers towards frameworks, towards complex. Like super complicated sort of software engineering approaches that stretch out the time it takes to actually build a thing.

Man, 100%. And it's the same thing with big corporations. 80% of the people don't do anything. It's like- It's not efficient. Your benchmark is like people building stuff that actually gets done and like for society, right? If we wanna save time, we should probably use technology that's simple, that's pragmatic, that works, that's not overly complicated. It doesn't make your life like a living hell.

And use a framework one that obviously solves a problem, a direct problem that you-

Of course, yeah, of course. I'm not saying you should code without a framework. You should use whatever you want. But yeah, think it's suspicious. And I think it's suspicious. When I talk about it on the Twitter, there's this army comes out. There's these framework armies.

I wanna ask the framework army, what have they built this week?

A couple thoughts -

yeah, some of the coding practices encouraged by early PHP *were* terrible (automatically converting CGI params to variables).

And honestly, I don't think Vanilla JS is is that bad to build with relative to jQuery, with a site like You Might Need jQuery you really can get done what you need to do. (Honestly I should look into what CSS libraries Levels uses - the shallow stuff is like 80% of the perception a site.)

Finally, I'm not quite as suspicious about the "follow the money" aspect as Levels is - or at least I'm more aware of the peer pressure aspect, that it feels like so many engineers have really learned to love their chains in terms of complexity... maybe it's a path to better job security somehow, maybe opinionated frameworks scale better for larger teams? But to me, it always seems to get in the way of getting things done in a way that's productive in the short term and maintainable over 5-10 years.

Levels view about the money involved reminds me of this 20 years old essay from Joel "Joel on Software" Spolsky, Fire and Motion. The first half is about the intermittent trouble of getting started being productive in a workday, but then he pivots to his time is an Israeli Paratrooper, where he learned the trick of Fire and Motion - keep moving and keep firing to make the other guy keep his head down. He writes:
Think of the history of data access strategies to come out of Microsoft. ODBC, RDO, DAO, ADO, OLEDB, now ADO.NET – All New! Are these technological imperatives? The result of an incompetent design group that needs to reinvent data access every goddamn year? (That's probably it, actually.) But the end result is just cover fire. The competition has no choice but to spend all their time porting and keeping up, time that they can't spend writing new features.
Sometimes it feels like the "flavor of the month" frontend webdev is a victim of some of that - along with engineers who are more interested in HOW something is done than what actually is done.

Sunday, September 1, 2024

PHP rewriting path names to index.php without trailing slashes and losing POST info

One drawback of "raw PHP" style coding is often the lack of a router... I've rolled my own at least once (with a mix of .htaccess style rewrites parsing out the path 'by hand' in scrip to a single router file) but usually I just punt by using "[approot]/[ACTIONNAME]/index.php" folders - letting the ability to link to "[approot]/[ACTIONNAME]/" as the URL hide my horrible indiscretion of using PHP. 

 (I do feel like the simplicity PHP offers is making some level of comeback - and for me it has a proven track record of stability and simplicity over decades - when you come back to code, it's - lo and behold - still working years later and most often not THAT hard to trace through, with plenty of transparency)

One mistake I vaguely remembered making before has to do with how Apache and/or PHP rewrites can lose POST information.

Lets say I was making an app for easily conducting surveys and was hosting it at myserver.com/survey/

If I had a form that started

<form action="/survey/save" method="POST">

I might be in trouble without trailing slash! Looking at the network tab, it looks like there's a jump from /survey/save to /survey/save/ (and from thence to /survey/save/index.php) and so information doesn't actually get POSTed. But including in the trailing slash lets it work just fine.