auto fileOrError = downloadFile();
if (fileOrError is error) {...}273 karma · joined October 27, 2018
auto fileOrError = downloadFile();
if (fileOrError is error) {...}Which is part of the problem. If you're not catching the exception, you don't need exceptions. You just need a way to log stuff, such as a trace, and exit the program. New languages such as Rust and Go encourage this explicitly - that is, use the ordained error path in the return value for expected errors, and only panic for catastrophic errors (or use panic in hotpath where return overhead has unacceptable performance impact and errors are super rare).
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p070...
> Programs bugs are not recoverable run-time errors and so should not be reported as exceptions or error codes. — We must express preconditions, but using a tool other than exceptions... migrate std:: away from throwing exceptions for precondition violations.
https://blog.stephencleary.com/2013/11/there-is-no-thread.ht...
Which part of the state, and when?
Is this your program?
// change anything, anywhere, in the entire database, the biggest state
execute_sql(user_input)
You might want controls around that state so not anyone can change it. It might be read only for some users - that is, immutable.Is this your program?
log_to_database(financial_event for $5.00)
You probably want your financial logs to be immutable. Nobody should be able to mutate that $5.00 event to be $500.00.Is this your program?
o.foo = complex_function(...)
... 1000 lines later ...
o.foo = null
... 1000 lines later in another file ...
o.foo.do_stuff() // oops! foo was set to null somehow - but where?
The above scenario has shared state with "foo". Somewhere it was set to null somewhere. It could be set to null anywhere in your program. Good luck tracking the bug. If "foo" was immutable, you would know immediately where null came from, because it can only be initialized one time. It lowers the cognitive load, knowing that certain actions are impossible makes it easier to focus on what matters.Is this your program?
thing = computation()
return thing + 2
Many program are a series of computations - fresh state is created on each line, nothing is mutated. There is no reason not to be using immutability. In fact, if immutability were throughout, a compiler wouldn't have to worry about things like aliasing.This is all the tip of the iceberg, there are many reasons to enjoy using immutability.
https://www.theatlantic.com/health/archive/2015/01/rethinkin...
https://www.vox.com/2018/6/13/17449118/stanford-prison-exper...
How often is ADHD misdiagnosed as a result? If it is hereditary, have we found the gene(s) which would enable us to pinpoint the diagnosis, possibly even before birth?
I also have trouble falling asleep and have made bad decisions in the past. I have effective strategies to mitigate. Do I actually have ADHD and need to take amphetamines? I am not saying this of you, but I find it disheartening when people say "it is just my genes, nothing I can do about it". It's fatalistic and a self-fulfilling prophecy. If there actually are unknown environmental factors, that attitude seems to be ignoring them outright. For instance, exposure to large doses of lead as a child might instead be incorrectly diagnosed and interpreted as "just my genes I guess". There are so many poorly understood chemicals swimming around our water supplies, food systems, cosmetics, etc. I wouldn't be surprised if we're taking drugs to bandaid something much deeper to blame.
// just copied some code into this while block, oops I copied an extra space out front...
while (...) {
if (...) {
...}
}
// after Ctrl+S tied to autoformat
while (...) {
if (...) {
...
}
}State of the art GCs are incredible - but there is a reason you see Java pioneering the GC area, that being that Java has the most to gain because of its tendency to create enormous amounts of garbage, which is a problem other language designs do not suffer from nearly as much, letting them get away with simpler GC while maintaining high performance.
And Fortran isn't the only game in town for high performance numerical libraries ;) There is large incentive to reinvent there, as legacy doesn't matter if the new thing has more performance - Eigen, cuBLAS/CUDA, and others are in C++, not Fortran as far as I'm aware. Fortran has momentum no doubt, but it has been on its way out for a long time.
Two major initiatives for many years in Java have been Loom and Valhalla. A cynical take on that is that Java is attempting to copy something that Go and C# (and others) have had and excelled at for a decade or more, and were designed to do from the start. Sometimes, at some point the expense and complexity of dragging decades of code forward (with all accumulated mistakes, design assumptions made based on now obsolete hardware, backwards compat constraints, etc.) outweighs the cost of going back to the drawing board to start again.
Unfortunately the more compatible you are with "V1" the more compromises you have to make. See: Kotlin, F#, TypeScript bending over backwards to maintain compatibility with the dominant language of their respective platforms. Not to mention C++. You have to admire the hutzpah of Python 3 level of changes. Some software should simply have a "sell by" date and be thrown out when it starts to stink.
That said I'm surprised more languages haven't attempted the approach of Rust with 'editions'.
> There are times, however, when it is useful to be able to make small changes to the language that are not backwards compatible. The most obvious example is introducing a new keyword... Editions are the mechanism we use to solve this problem. When we want to release a feature that would otherwise be backwards incompatible, we do so as part of a new Rust edition.
[https://doc.rust-lang.org/edition-guide/editions/index.html]
var i *int = nil
var x interface{} = i
if x != nil {
I assigned `nil` to `x` and yet `x` is not nil. Implicit conversions aren't unusual in programming but in Go they stand out a bit. The closest analog I could find was abusing implicit conversion operator in C#. But even that's pretty explicit and you can tell something odd is happening. Thing1 i = null;
Thing2 x = i;
if (x != null)
{
System.Console.WriteLine("x is not null");
}
class Thing1
{
public static implicit operator Thing2(Thing1 c) => new();
}
class Thing2 {}Isn't the point of SSR to avoid needing to have the client make additional requests for the first render? If I return something like <div dangerouslySetInnerHTML={fetchWithGrpc(myGoFunc)} /> that's not SSR. Perhaps I'm missing something.
Sounds like you'd love https://minus.social/ where you are limited to 100 posts, period.
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.
Have heard this sentiment in more than one comment in places like HN. "The {tech} is great, but the culture was ... so I'm not putting {tech} on my resume". And So it becomes a self-fulfilling prophecy :). Yet some tech seem immune to this. They don't say "X is great but the culture was crap, so I'm abandoning X", they say "X is great but the culture was crap so I'm changing jobs".
It really drives home that culture is critical, and even the worst tech can be tolerable if it is thought of as cool. Though of course the thought of abandoning ship to learn the latest and greatest solely to avoid legacy C++98/Spring/WebForms/whatever is naturally appealing.
I don't expect a web designer to know how NAND gates or how to program in C because it's irrelevant. If they spent time learning that on the job, that's likely a waste of time. Abstractions exist for a reason.
I agree completely though that lazy people are out there. Professionals should always be learning and trying to improve their craft. Learning the bare minimum shouldn't be the default.
LSP appears to be alive and well with editors that are not VS Code. The entire point of LSP is to decouple the text editor from the language, and it works.
https://github.com/search?q=language+server+protocol
If VS Code has more support for LSP it is because Microsoft has poured money into it, invented LSP to begin with, and popularized it with VS Code to begin with.
https://www.ft.com/content/01b7c7ca-71ad-4baa-bddf-a4d5e65c5... https://www.reuters.com/world/china/exclusive-china-readies-...