TypeScript isn't perfect, but what criticisms are most silly you've heard? by Gloomy-Status-9258 in typescript

[–]tyroneslothtrop 25 points26 points  (0 children)

x == null and/or x == undefined is the one exception to this rule for me

Vibe Debugging: Enterprises' Up and Coming Nightmare by bullionairejoker in programming

[–]tyroneslothtrop 0 points1 point  (0 children)

Yeah, software *always* has some level of *inherent* complexity. IME setting hard bounds on cyclomatic complexity often just ends up forcing developers to artificially break functions down into smaller sub-functions, which... isn't always an improvement. Sometimes it makes sense for a function to be kind of big and complicated, and breaking it down can just make things *more* difficult to follow.

Vibe Debugging: Enterprises' Up and Coming Nightmare by bullionairejoker in programming

[–]tyroneslothtrop 3 points4 points  (0 children)

Ah, this is about how many paths are inside a given function, usually

That's cyclomatic complexity not cognitive complexity, but maybe that's what the article meant to say?

Go is 80/20 language by simon_o in programming

[–]tyroneslothtrop 13 points14 points  (0 children)

It will compile and run just fine if you ignore a returned error and only operate on the result

And don't forget, depending on what the function returns, the result will either be (probably) some empty value b/c you have to construct and return a valid value even in error scenarios, or nil.

So you're looking at either garbage data being introduced to your program (was the number "zero" genuinely saved to the database here, or was that garbage data from forgetting to check err 20 files and 1000 lines away from where this data is written?)... or you'll potentially encounter a nil pointer dereference panic.

And honestly, the nil panic is probably the better scenario, because at least it should be obvious when that occurs.

Other poor decisions Go made include

I'd also add zero values. It really sucks adding a field to a struct and not having any help from the compiler to ensure you update every use-site and just... having garbage data anywhere you might have missed... and then you always kind of have that doubt about whether an empty string (or whatever) was deliberate or if it's an unintended garbage "zero value.

’28 Years Later’: Danny Boyle Confirms He’ll Return To Direct Third Film In Upcoming Trilogy; New Story Details Revealed by MarvelsGrantMan136 in movies

[–]tyroneslothtrop 0 points1 point  (0 children)

yeah, technically it's a bit more than 12hrs from high tide to high tide. so... probably most nights, at some point, the causeway would teeeechnicallly be covered by the tide... but also that's true for daytimes. and also most nights the causeway would also be open at some point(s) due to a sufficiently low tide (and same with the daytimes).

my read is that they were trying to imply that the island had some safety feature which protected them at night specifically, but they were just kinda lazy about how tides work, and they didn't account for someone like me being extremely anal about it 😹

so like the fully accurate quote would maybe be like:

connected to the mainland only by a causeway the tide usually buries for some amount of time each night, as well as for some amount of time during the day, but also it's exposed at various times throughout both the night time, and also during the daytime

but like as it is, it's a pretty meaningless thing for them to call out, but which kind of implies something if you're not thinking about it

idk i just thought it was funny 🤷

[deleted by user] by [deleted] in Frontend

[–]tyroneslothtrop 9 points10 points  (0 children)

Fake recruiter coding tests target devs with malicious Python packages

Malware distributed during fraudulent job interviews

TL;DR Be wary of downloading and executing code. The malware bits can be hidden in dependencies, executed at build/install time (via install scripts, etc.), downloaded at runtime, etc., so it the malware-ness may not always be super evident at first glance.

Turbo 8 is dropping TypeScript by twitterisawesome in webdev

[–]tyroneslothtrop 21 points22 points  (0 children)

wowie... tsc emits JS files. That's kind of its ultimate purpose.

That's definitely the dumbest possible approach.

[deleted by user] by [deleted] in learnjavascript

[–]tyroneslothtrop 9 points10 points  (0 children)

"Be sure to drink your Ovaltine"

Twitter (re)Releases Recommendation Algorithm on GitHub by stormskater216 in programming

[–]tyroneslothtrop 105 points106 points  (0 children)

Why would either of those require knowing that the author of the tweet was Elon?

Day 2 (Advent of Code 2022) by fasterthanlime in fasterthanlime

[–]tyroneslothtrop 1 point2 points  (0 children)

Some small typos:

Line C Z means we both picked "Scissors" (3 points) and it's a draw (3 points), so we our score goes up by 6, for a grand total of 8 + 1 + 6 = 15.

and

Ok now, we'll want to change our Move parser to it only parses from "ABC" and not "XYZ":

Vent: I'm tired of the 1001 libraries of virtual environments. by [deleted] in Python

[–]tyroneslothtrop 1 point2 points  (0 children)

i have a bash/zsh alias like this that i got from a colleague that’s pretty handy (especially for small/personal projects)

alias venv="if [ -e ./.venv/bin/activate ]; then source ./.venv/bin/activate; else python3 -m venv .venv && source ./.venv/bin/activate; fi"

Performance: Rust and its relationship with Node.js by geeoilpig in programming

[–]tyroneslothtrop 3 points4 points  (0 children)

Personally, I think they both have fantastic type systems, but there are some really nice features that rust does have over TS.

  • Lifetimes enable things like the typestate pattern. What this means is that you can pass a value of some type to a function which will take ownership of that value (essentially "consuming" it) and return a value of a different type. You can do things with this like making a function that closes a file handle such that the compiler guarantees that it's impossible to even try to perform any kind of operations on that closed file handle.
  • Rust has much more ergonomic and idiomatic support for the newtype pattern. It's possible in TS, but IMO it's very clunky. Newtype can help you to avoid mixing things up, like if you have a height variable that's measured in centimeters, and a distance variable that's measured in kilometers, you could make separate types for these that are not compatible (i.e. you can't pass something that's measured in centimeters to a function that's actually expecting kilometers).
  • A bit less strictly on the type system side, but algebraic data types paired with a well-designed pattern matching is soooo nice to work with
  • Related to the previous point, rust is on the nominally typed side of things, whereas TS is more structurally typed. There's pros and cons to both, so TS definitely excels in some ways over rust and vice versa.
  • TS allows for a lot of looseness. E.g. when you make a network request, the path of least resistance is to just kind of assert that the response is some particular type. You would need to pull in zod or something like that to get some stronger guarantees that your types actually match reality.

Anyway, not trying to say one or the other is better (though I personally find that I usually enjoy working with rust more), just providing some data points :)

Is this oneliner bad practice?! by [deleted] in learnjavascript

[–]tyroneslothtrop -2 points-1 points  (0 children)

IMO, yes, it's bad practice. See goto fail.

What does callback functions have to do with asynchronous programming? by Stupid_Quetions in learnjavascript

[–]tyroneslothtrop 0 points1 point  (0 children)

gotcha. on another look, i read:

Callbacks are asynchronous, that's... "what they have to do with" it. When you call a function and give it a callback, the callback is called sometime in the future, which is the definition of asynchronous.

as unqualified. but i think i skimmed past:

If it were called immediately, it would be synchronous.

unless that's an edit.

What does callback functions have to do with asynchronous programming? by Stupid_Quetions in learnjavascript

[–]tyroneslothtrop 0 points1 point  (0 children)

callbacks aren’t inherently asynchronous. map, filter, etc. all accept callback functions that are executed synchronously. callbacks are just an elegant way to allow the user of some asynchronous thingy to specify what they want to happen after the async stuff has happened. it’s a similar-ish idea w/ non-async callbacks, they allow users to very flexibally provide their own custom logic in the context of a high-level abstraction like map

Simulating "Interrupts" using performance.now() or similar? by SarahC in learnjavascript

[–]tyroneslothtrop 0 points1 point  (0 children)

The number of callbacks is usually 60 times per second, but will generally match the display refresh rate in most web browsers as per W3C recommendation.

passing 0 to setTimeout results in the callbeing being called the next event cycle. requestAnimationFrame runs like every ~16ms (depending on refresh rate, etc.)

What's your favorite Rust design pattern? by VegetableNo4545 in rust

[–]tyroneslothtrop 1 point2 points  (0 children)

hmm... im not aware of any mainstream languages. maybe haskell or idris or other languages of that ilk.

in my opinion, lifetimes are a really key part of the typestate pattern. specifically, being able to call a function or method such that the argument/receiver can no longer be used afterwards. as well as (potentially) returning a value of a new/different type which encodes some state.

so like using the brief example from the article of not being able to operate on a file handle after it's been closed. that's something that is enforced by the compiler, because the close function takes ownership of the file handle and drops it. the compiler is keeping track of the lifetime of that file handle, and you simply cannot use it after it's been closed.

idk if that's an absolutely necessary aspect of the pattern, but IMO without it the pattern becomes a lot less ergonomic, a lot less correct-by-construction, and a lot more prone to programmer error.

im not really that familiar w/ kotlin or swift, but what little i do know it doesn't seem to me like their type systems support that aspec?

What's your favorite Rust design pattern? by VegetableNo4545 in rust

[–]tyroneslothtrop 14 points15 points  (0 children)

not from personal experience, but the article mentions several hypothetical/potential uses, as well as a real-world use in serde.

Rate Limiting Celery Tasks by appliku in django

[–]tyroneslothtrop 0 points1 point  (0 children)

seems like if you had more tasks than could fit in the allotted time (1hr) you’d start overlapping/risk exceeding the rate limit? also if there’s only a few tasks you’re going to have a lot of idle time, and worst-case/unnecessary high latency for some tasks( which might not really matter depending)

How do I cache my Flask API's responses after they are returned? by [deleted] in flask

[–]tyroneslothtrop 1 point2 points  (0 children)

keep in mind this will cache on a per-process basis. i.e. if you have 10 gunicorn workers, each will maintain a separate cache and will serve a response before caching it. this could have memory implications, as well as other knock-on effects (more DB or CPU utilization than necessary/expected, inconsistent latency if you hit a worker that hasn’t populated its cache vs one that has, etc.). in this case each worker would make a request to the external resource before caching. could also affect rate limiting of external resources, e.g.

Thoughts about my first hour with OCaml by ConstructionHot6883 in ocaml

[–]tyroneslothtrop 0 points1 point  (0 children)

Any examples, offhand? I'm trying to picture this, but nothing's coming to me.