225 karma · joined Aug 2, 2022 (4y ago) · 102 submissions
comment 3y ago · link · parent
Once you get it, you will realize how much of a game-changer it is. This is the reason Bun is going to win.
comment 3y ago · link · parent
People get so intimidated by these huge frameworks and get FOMO, that they never try to build something from scratch.
React seems simple, but if you tried to understand what is going on under the hood it would take you months.
Simple should be: can you trace through all the code yourself. Like Backbone.js for example.
Plus, there is already so much rendering complexity under the hood in browser engines. The DOM and CSS are already incredible abstractions available for you to use.
I really don't get what is so bad about just having some object to manage a dom element's rendering.
Create a single relational source of truth for your data. Then create some view models that listen to this source of truth. Then make your objects listen to these view models.
This vdom diffing stuff is so overated.
If you have a list of items, and a new item is inserted, I can just insert that directly into the dom. If I render a different entity and it uses mostly the same dom elements, it's really not that hard to tell say: here are some new props, compare them with your old ones, and do what you think is best. React promises this for the entire app but its all magic. I want control of my rendering so I can make things fast. Debugging perf issues in React is insane. Good luck debugging anything.
comment 3y ago · link · parent
Declarative build systems obfuscate so much without providing the proper debugging and error-handling capabilities.
Build systems should be imperative and type-checked. A simple script that a user can step through and observe what is happening.
Makefiles suck because they are not type-checked.
The only abstraction you need is some kind of dependency graph. But then it should be completely transparent to the user so they can easily understand it.
66.
Tell HN: The terminal shell is a nightmare
1 points · by grumblingdev · 3y ago · 4 comments
comment 3y ago · link · parent
I realized that when I call a bunch of functions one after the other, I want to be able to reference them. I would have to put them in an array.
Then I thought why do I have to make this choice case by case. If only everything was a list…
I now want to see how I can shoehorn this into TypeScript. Maybe with macros or transpilation or something.
Then I want to see what cool things I can now do.
The only thing that gives me pause is that the language is insane to read and when you look at the implementation of Lisp defun and defmacro the code gets pretty wacky.
Figuring out what is a primative and what is just lists is very difficult.
I wonder if there is a less purist Lisp out there that looks nicer.
comment 3y ago · link · parent
But I think perf issues did it in from this design choice.
I'm keen to explore Emacs more.
Plugin systems are one of the hardest things in software (but also look the easiest from the outside).
comment 3y ago · link · parent
There are many flags that change the behavior of the file system calls that would be made...such as getting additional information.
To support all the formatting commands, the piped output of `ls` would need to be very verbose and structured too...like json or something.
They had to draw boundaries of functionality at some point.
So the unix idea of "one thing" was probably defined a bit more vaguely or more end-user use case related. Convenience seemed to be king.
It would have be nicer if they could have added a shell-like pipe syntax to C (and designed the code in a more modular and stream-like way).
In the `ls` [source code][1] you can see simple blocks of steps like:
if (!file_ignored(file)) {
...
sort_files ();
print_current_files ();
clear_files ();
}
For example the `file_ignored` function in `ls` would have made a nice reusable library (with standardized configuration params) and a cli tool (with standardized flags).Missed opportunity to unify the shell and C, but I guess SmallTalk was kicking around at that time which went a whole lot further.
It's funny that we are still very much lacking this unification...
We don't have a high-level interpreted language that can also perform well as a system's language.
New systems languages are popping up all the time, but they are more and more hardcore (looking at you Rust). They don't embrace any aspect of scriptability.
The best effort I can think of is https://www.modular.com/.
Surely though, a native TypeScript-based language is the way. It by far has the nicest syntax out of the popular scripting languages today.
We have come so close...like with Dart...but still everyone seems to be avoiding the inevitability.
[1]: https://github.com/wertarbyte/coreutils/blob/master/src/ls.c
comment 3y ago · link · parent
And yet everyone still uses `ls`.
comment 3y ago · link · parent
Good point.
You have to hand it to them though, that shell commands are still the least-typing way to do something compared to every programming language out there.
Like if you gave the user an always-on JavaScript or Python repl, shell commands are still going to win every time.
There are so many JS functions I have that I wish would just get automatic cli interfaces...instead of having to go through the ceremony, or use a repl, or something like that.
comment 3y ago · link · parent
I have recently had the thought that this is mostly what software architecture is...at some level.
It's about where we draw the boundaries around code to make it easy for humans to understand.
Imagine taking an existing repo, and extracting every block of code into a function, and then moving them into their own separate file in one big folder. You could extend it to all the libraries of your code, and of those services we communicate with over the network too.
This would look a bit like a debugger symbol table. It's closer to how the computer understands the program.
The app still runs. It's just hard for people to understand what is going on.
Software architecture is simply the grouping of these functions to some extent.
It's not a foolproof analogy, because there are some decisions to be made about implementation details of things, but at some level of abstraction you would find the same operations need to be run.
Just an interesting thought.
> The question of how to architect such software is still an open one.
I find a problem we face with architecture discussions is that its always about tradeoffs that are not immediately apparent.
And it takes a lot of mental effort to remember why something is a bad idea.
The way we discuss it is limited by plain text. It's hard to demonstrate a system evolving over time in a concise manner.
Architecture should be evaluated by throwing a spec at it, and then changing every part of the spec (including adding perf requirements) and seeing how long it takes to make the changes, and how many bugs it has.
comment 3y ago · link · parent
I often wonder how much of the code we write is actually doing something not possible in another language. Like runtime-specific, or low-level stuff. Most of the business logic...loops and if statements are rather similar.
comment 3y ago · link · parent
It's much easier to follow the control flow with hoisting. I see `run()` being called, and then I want to know what it is. In other languages you are usually seeing a huge bunch of inline functions and then asking: okay, but when and how is this actually called?
def foo():
def run():
print("hi")
run()
function foo() {
run()
function run() {
console.log('hi')
}
}comment 3y ago · link · parent
There are lots of singletons in OO. I find it useful to add static metadata (not state) to them, without having to escalate them to a class. I guess Java has decorators for the same purpose. I'd really like decorators for functions in TypeScript though.
comment 3y ago · link · parent
The fact that Functions are Objects that can have properties/methods is supremely undervalued.
Are there other languages that do this so nicely? It's the perfect blend of OO and functional.
Programming is mostly about gradually figuring out the right design I find. JS/TS let's me evolve things naturally without big rewrites.
function foo() {}
function bar() {}
function baz() {}
const commands = [foo, bar, baz]
// Run commands
commands.forEach(x => x())
foo.help = 'This does something'
// Describe commands
commands.forEach(x => console.log(x.help))
// Add some state via closure.
const config = {}
function foo() { config.blah }
// Add some state using partials.
function _foo(config) { config.blah }
const foo = foo.bind(null, config)
I can flexibly do what I need, without ever having to define a class like `Command`, which I probably don't even know what it should be yet.This premature naming of things in OO creates so many dramas.
It avoids things like `VideoCompressor#compress()`, `VideoSplitter#split()`. You don't have to think: what state belongs in which class...you just call the function and pass it what it needs.
comment 3y ago · link · parent
I've realized that things always need to change in unexpected ways. Objects are sticky, people just cram stuff into them instead of re-thinking the hierarchy properly.
There probably exists a really nice and cleanly separated object-hierarchy for a codebase at a given point in time, but requirements always evolve too rapidly to enjoy this for too long.
comment 3y ago · link · parent
You'd think something like directory watching would have a clear set of events that would make nice objects with consistent meanings, but in my experience file watching gets crazy complicated, and can have all sorts of edge cases.
Just take a looked here for all the various edge cases that crop up: https://github.com/paulmillr/chokidar/issues
Then you have linux, windows, macos, and maybe you want to abstract over some underlying implementation like chokidar vs fb/watchman vs webpack/watchpack. Every new OS release could also cause things to change. A big leaky abstraction.
So usually its going to be a bunch of if-else statements hacked together to get around edge cases, and have to be revisited later on.
Any attempt to abstract this into objects, just obfuscates things. And OO forces you to name things, when in fact they might be un-nameable. `FileSystemModifyEventExceptWhenXAndYAndSometimesZ`.
The behavior might rely on a series of events together, so the object hierarchy must be re-worked.
OO has this rosy idea that we just have to come up with the perfect hierarchy, but things change in unexpected ways, and everything must have a descriptive noun.
comment 3y ago · link · parent
Why? Do you have an example to better explain?
If find people rarely talk about the evaluation criteria for which approach to programming is better. That is, what are you optimizing for?
comment 3y ago · link · parent
It's the small things in programming that can make a huge difference. It always felt like I should be using the C++ way because it was slightly dry-er and looked nicer, and I could have all these OO features.
Like when you see `int get_numer(void *r)` or Python's `def get_numer(self)`, or Go's `func (rational *Rational) GetNumer() (n int)`, you think: "how silly, why does the object pointer need to be in scope, just use `this`". But this tiny thing is liberating. It allows you to see that everything is just functions operating on data. And that a "method", is just a function that is taking _the entire object_ as a parameter...and hence a dependency. Which allows you to think: hmm, does this function really need to depend on the entire object...maybe it can be a separate utility function all by itself without any connection to the class. And maybe it doesn't actually need access to any of the other functions in the class...and maybe the class could be split up...etc.
I just watched a [talk](1) by Alan Kay the inventor of SmallTalk and the phrase "object-oriented" who never stops shitting on C++.
Yet OO is still absolutely everywhere.
comment 3y ago · link · parent
Imagine if TypeScript/JSX was available native in the browser requiring no transpilation step, and we dropped support for any package requiring some exotic transpilation.
You could easily step through your entire codebase first and thirty-party without battling source-maps or minified files.
Libraries that required adding a compilation step and a complex dev server would be shunned. Having this compilation step in place means it's easy to just pile on tons of functionality, import hooks, AST transformations, etc. which causes the complexity.
comment 4y ago · link · parent
Completely disagree. I believe it will come eventually. Check out AssemblyScript for example.
People choose TypeScript because it's simple and easy. They choose Rust because they need the features and ecosystem that are not available in another syntax as of yet.
comment 4y ago · link · parent
Interesting point, hadn't thought about this before.
> TS doesn't have syntax for value vs reference types or memory ownership/lifetimes...if you kept the syntax similar to TS, then new features may end up looking bolted on and forced
I would argue that the vast majority of code in a low-level language doesn't care about manual memory access or pass by val/ref. It's all abstracted away into libraries. It just comes down to a different syntax, but they are all doing the same thing. As seen here: https://rosetta.fiatjaf.com/compare/TypeScript/Rust/.
Most of the time we are just passing around references anyway. So why no make this the default implicit case, and then when you need something exotic, add syntax then.