x = read_guess(0)
y = read_name("what's your name: ", len(x))
z = read_guess(len(x)+len(y))
If you read(0) twice, you get the same value both times.fn do_stuff(offset: int) -> (string, int) { x = read_guess(offset) y = read_name("what's your name: ", offset + len(x)) z = read_guess(offset+len(x)+len(y)) new_offset = offset+len(x)+len(y)+len(z) return ("name is: {y}, guess is: {x}", new_offset) }
x = read_guess(); y = io.read_int("what's your name: "); z = read_guess();
How would your system ensure x and z are the same?
At the term level, you could just let your function have a function as a parameter `read_file: IO -> String`, vs. annotating it with some kind of type-level "filesystem effect". And the former is a lot more flexible over time.
There's also a great talk on the matter [1], if somebody is interested in formalities.
The worst case is actually worse than when types are mandatory, since you can get an error in the wrong place. For example, if a function has the wrong type inferred then you get an error when you use it even though the actual location of the error is at the declaration site. Type inference is good but there should be some places (ex. function declarations) where annotations are required.
[1] https://koka-lang.github.io/koka/doc/book.html#sec-return
How is:
const count = (amount: number) => (amount > 0 ? [...count(amount - 1), amount] : []);
Succinct and better? It’s fewer lines. It uses recursion. But it’s obtuse and illegible syntax diarrhea that takes more time to grok.The for loop example above, while simple, is easily understood. A junior engineer could fix it. Is it faster? No. Is it easier to understand? Yes. I like the final example as well.
Look, I’m all for being clever when cleverness is needed but some of you JS/TS folks take it to the extreme. I want to be able to read my codebase, not perform archaeological studies. I have the same issue with Rust syntax as well in places.
I will praise the article on this though, optimizations do matter and having something execute orders faster will improve your overall experience. It doesn’t have to be cuneiform. If you must be clever, wrap it in an abstraction that is well documented because you don’t live forever and neither will your code, make it easy(ier) on the next person. While you can nest a recursive function in a tertiary statement coro, don’t. Fire is cool but also burns.
Btw, bun is blazingly fast. I look forward to more.
const count = (amount: number) => {
if (amount > 0) {
return [...count(amount - 1), amount]
} else {
return []
};
} <DoStuff args={...}><DoMoreStuff args={...}> <DoEvenMoreStuff args={...}/> </DoMoreStuff> </DoStuff>
vs DoStuff(DoMoreStuff(DoEvenMoreStuff()))
Both of them you would split into indented lines when they become too long. And 1 becomes too long much faster.Also with 2 you can do
const todo = DoMoreStuff(DoEvenMoreStuff());
DoStuff(todo);
where as with 1 you cannot. const todo = <DoMoreStuff args={...}><DoEvenMoreStuff args={...}/></DoMoreStuff>;
<DoStuff args={...}>{todo}</DoStuff>I once had a chat with a founder who merged his startup with a SPAC. He mentioned that the allure wasn't just the capital but the perceived simplicity of the process, compared to a traditional IPO. But looking back, he felt that the rigorous scrutiny of the traditional path might have forced his team to address underlying business challenges they'd later face.
in any event the real question here isn’t whether SPACs as a vehicle are intrinsically flawed, but if the market’s appetite for risk, combined with the allure of quick liquidity, blinded many to fundamentals during the 2020 bubble. With any financial innovation, there's often a cycle: initial excitement, over-extension, contraction, and then matured understanding. Perhaps we're in the contraction phase for spacs, but they might still find a place in a more judicious market
I'm a little more cynical, I think the cycle is: a new financial invention comes out, greed causes people to people to pump money into it, eventually the bubble pops or regulators step in. We've seen it time and time again: the dot com bubble, the subprime mortgage bubble, SPACs, and now/soon (IMO) with PE. My question is how many times this has to happen before we stop viewing it as an isolated with specific product and start to see it as a system issue with our financial system.