Readit News logoReadit News
MrJohz commented on Common Rust Lifetime Misconceptions   github.com/pretzelhammer/... · Posted by u/CafeRacer
nromiun · a day ago
> It's possible for a Rust program to be technically compilable but still semantically wrong.

This was my biggest problem when I used to write Rust. The article has a small example but when you start working on large codebases these problems pop up more frequently.

Everyone says the Rust compiler will save you from bugs like this but as the article shows you can compile bugs into your codebase and when you finally get an unrelated error you have to debug all the bugs in your code. Even the ones that were working previously.

> Rust does not know more about the semantics of your program than you do

Also this. Some people absolutely refuse to believe it though.

MrJohz · a day ago
I think the key idea is that Rust gives you a lot of tools to encode semantics into your program. So you've got a much greater ability for the compiler to understand your semantics than in a language like JavaScript (say) where the compiler has very little way of knowing any information about lifetimes.

However, you've still got to do that job of encoding the semantics. Moreover, the default semantics may not necessarily be the semantics you are interested in. So you need to understand the default semantics enough to know when you need something different. This is the big disadvantage of lifetime elision: in most cases it works well, but it creates defaults that may not be what you're after.

The other side is that sometimes the semantics you want to encode can't be expressed in the type system, either because the type system explicitly disallows them, or because it doesn't comprehend them. At this point you start running into issues like disjoint borrows, where you know two attributes in a struct can be borrowed independently, but it's very difficult to express this to the compiler.

That said, I think Rust gives you more power to express semantics in the type system than a lot of other languages (particularly a lot of more mainstream languages) which I think is what gives rise to this idea that "if it compiles, it works". The more you express, the more likely that statement is to be true, although the more you need to check that what you've expressed does match the semantics you're aiming for.

MrJohz commented on JSDoc is TypeScript   culi.bearblog.dev/jsdoc-i... · Posted by u/culi
john01dav · 2 days ago
> - I like languages that let you decide how much you need to "prove it."

Rust is known for being very "prove it," as you put it, but I think that it is not, and it exposes a weakness in your perspective here. In particular, Rust lets you be lax about types (Any) or other proved constraints (borrow checker bypass by unsafe, Arc, or cloning), but it forces you to decide how the unproven constraints are handled (ranging from undefined behavior to doing what you probably want with performance trade-offs). A langauge that simply lets you not prove it still must choose one of these approaches to run, but you will be less aware of what is chosen and unable to pick the right one for your use case. Writing something with, for example, Arc, .clone(), or Any is almost as easy as writing it in something like Python at the start (just arbitrarily pick one approach and go with it), but you get the aforementioned advantages and it scales better (the reader can instantly see (instead of dredging through the code to try to figure it out) "oh, this could be any type" or "oh, this is taken by ownership, so no spooky action at a distance is likely").

MrJohz · a day ago
In practice, though, writing stuff with `Arc` or `.clone()` or `Any` is not as easy as it would be in Python because you've got to write a bunch of extra boilerplate. It's much easier to have local `i64` values that you can pass around as `Copy`. So if all you need are local i64s, then you'll take the easier option and do that.

The same is true at multiple levels. `.clone()` is relatively easy to use, although once you learn the basic rules for referencing, that also becomes easier. `Arc` solves a specific problem you run into at a certain point sharing data between threads, but if you're not sharing data between threads (and most of the time you're not), it's just boilerplate and confusing, so you might avoid it and at worst use `Rc`. `Any` is rarely an obvious choice for most contexts, you really are going to only use it when you need it.

The result is that for most simple cases, the precise and "proven" option is typically the easiest to go for. When you deal with more complicated things, the more complicated tools are available to you. That seems exactly what the previous poster described, where you can decide yourself how much you need to prove a given thing.

MrJohz commented on Adafruit: Arduino’s Rules Are ‘Incompatible With Open Source’   thenewstack.io/adafruit-a... · Posted by u/MilnerRoute
1718627440 · a day ago
Is this actually true? Doesn't the action of directing someone to compile this code, mean they are allowed to compile this code? Of course they are not allowed to do anything else, but this is what I want as a user. I think it is more, that the vendors want to push the user to grant them more rights than what would be strictly necessary for them to do they job they "sell".
MrJohz · a day ago
This is what's been explained to me before. The problem is that lawyers don't necessarily work on the basis of "if it seems reasonable that the user allowed this, then this is allowed". Their goal is to make a contract that, if they need to go to court, will make their job as easy as possible. So it's not enough to say "obviously the user pressed the 'compile' button and we needed to do all this stuff to make that happen, here's all my technical experts who agree", instead they would rather say "paragraph 3 subsection 12 clearly allows this behaviour and the user has agreed to it".

It's also, as I understand it, the reason why law has so much of an emphasis on seemingly magic phrases that you copy and repeat in all sorts of different places. These are phrases that have already been tested and have a meaning that has been made clear in a court of law, so if you need to go to court to defend them, you can pull up the existing case law on the subject and rely on that, rather than having to analyse exactly what the new wording means. Hence why these T&C documents tend to have a lot of fairly standard phrases that don't obviously mean what you expect them to mean.

MrJohz commented on Adafruit: Arduino’s Rules Are ‘Incompatible With Open Source’   thenewstack.io/adafruit-a... · Posted by u/MilnerRoute
b112 · 2 days ago
That's not needed though. No licensing is required.

Code is copyright without any licensing. The hardware is not licensed, I don't sign a license or agree to one when buying a car or microwave.

You can find edge cases, but the point is no licensing is actually required.

MrJohz · 2 days ago
In this context, the license is for using the Arduino Studio application. This is hosted by Arduino, and therefore needs to take user input, save it and work with it. As I understand it, this puts them in a complex situation: they don't own the code you've written (obviously), but they do need to do things with it like compile it and run it (when you press the button in the IDE). They're also hosting the code and therefore partly legally responsible for it.

At the very least, you need some sort of user agreement to specify the things you can do with their content, otherwise you can't really do it because it's their content and you're not allowed to mess with it by default. (Like you said, code is copyrighted by default.) You also need to specify the things that are necessary by law because you are hosting that code and therefore in part responsible for it. You also don't want to make the user sign a new agreement every other week if you add some new feature that they need to agree to use, because the cost of all those legal documents is prohibitive, and it's also very bad UX.

Added to this the fact that lawyers are naturally very conservative as a profession (generally only doing things that have been proven successful, rather than avoiding things that have been proven unsuccessful), and it's easy to see why these sorts of agreements tend to be more expansive than they perhaps need to be, in order to ensure the company is fully protected.

MrJohz commented on JSDoc is TypeScript   culi.bearblog.dev/jsdoc-i... · Posted by u/culi
apatheticonion · 2 days ago
You can define a declaration file alongside its target however the target does not use the types defined within its declaration within itself - only consumers see the types.

There are three issues with that.

The first is that JSDoc doesn't support everything you need in TypeScript and there is a lot of inlining (like typedef causes collisions, there's no importing a type without also re-exporting it from the importing file unless you inline the import)

The second is that JSDoc isn't picked up from imported libraries (or at least I don't think it is?)

Lastly, you still need a transpiler to remove the comments and build d.ts files.

In the end, JSDoc isn't practical for projects. The header file strategy means you don't need to transpile ever (only a typechecker) and you'd get the full suite of TypeScript functionality - at the cost of synchronization overhead.

For a project using JSDoc, you'll graduate to TypeScript when there is sufficient complexity anyway. Migrating from a d.ts file is way easier (potentially automatable) than migrating from JSDoc.

MrJohz · 2 days ago
The problem with the header file strategy is that TypeScript doesn't have total type inference. That approach works e.g. in OCaml, where you can (optionally) type the boundaries of the function and everything inside the function can always be inferred. But TypeScript works differently and doesn't support that approach. So fundamentally, what you're describing isn't really possible without using a very restrictive subset of TypeScript that can be totally inferred or having very broad type definitions.

So even if TypeScript did check the header file against the implementation, you'd still need additional annotations inside the implementation file. At that point, why not put all the annotations inside the implementation file directly?

Regarding your points:

1. JSDoc does support everything that TypeScript supports (that's the point of this article), although it does not necessarily support it as cleanly, hence why projects like Svelte typically use DTS files to define the project's types, and have those be imported inside JSDoc annotations. It's not perfect, but it gets you a long way.

2. You're right, JSDoc isn't picked up from imported libraries, but if you're publishing a library, you'll have a build script there, and at that point it's typical to generate the DTS files and pack those with the source code. That seems fairly reasonable to me — while developing, you don't need to worry about building files, but then when packaging and releasing you do.

3. You don't need a transpiler with JSDoc, the point behind JSDoc is that it's literally just the pre-existing JS documentation syntax. You can (and should) leave the comments in. Even if you're using TypeScript syntax, you should have JSDoc annotations (although adding the types to those annotations is redundant in that case). You can also just include the DTS files. As long as they're only imported from JSDoc, the runtime won't see them.

Personally, having tried out JSDoc-based TypeScript, I'd rather just use the native type stripping in Node for development, and keep with TS syntax, but there are large projects that have made the opposite choice, most noticeably Svelte. So I don't think it's a given that JSDoc users will inevitably graduate to TypeScript (especially when projects have gone in the opposite direction).

MrJohz commented on JSDoc is TypeScript   culi.bearblog.dev/jsdoc-i... · Posted by u/culi
apatheticonion · 2 days ago
Personally, given the limitations of JSDoc, I'd like to see a header-file like definition system for build-less applications (like libraries).

    /
      index.js
      index.d.ts
Where values in `index.js` can be typed in the header file with complete TypeScript syntax and those types are present in the target file via intellisense and type checking

    // index.js
    function useStr(x){} // has intellisense for "string"

    useStr("Hello")
    useStr(42) // IDE and type checker error
And

    // index.d.ts
    declare function useStr(x: string): void

MrJohz · 2 days ago
This can be done, and is done in some projects, but the problem is that you need to manually maintain both sets of files, which can easily go out of sync if you're not careful. You also lose out on the ability to check your own code - using the header file you've written there, you can't really check the implementation of `useStr` to check that it works.

The advantage of JSDoc is that the TypeScript compiler treats it as equivalent to TypeScript source code, which means you've still got access to type checking inside your functions.

One thing I've seen in a few places is still to have DTS files that declare all sorts of types that are used in the application, and then have those files imported by JSDoc comments. That way, you've got TypeScript syntax for your types, which tend to get bulky and difficult to read in JSDoc syntax, but you still don't need a build system because the DTS imports are ignored completely at runtime.

MrJohz commented on Adafruit: Arduino’s Rules Are ‘Incompatible With Open Source’   thenewstack.io/adafruit-a... · Posted by u/MilnerRoute
MrJohz · 2 days ago
It's a bit odd that most of this article is various claims from one of Arduino's competitors being taken at face value, especially when the EFF spokesperson generally seems to think the new terms broadly make sense, albeit with some criticisms.

It sounds like Adafruit are just trying to sow some outrage here.

MrJohz commented on Incomplete list of mistakes in the design of CSS   wiki.csswg.org/ideas/mist... · Posted by u/OuterVale
wanderingstan · 5 days ago
I’ve gotten in several arguments over the years where webdevs insisted on showing tabular data using flexbox or hardcoded div widths or worse. They insisted that html tables were never ever to be used and couldn’t be persuaded.
MrJohz · 5 days ago
In fairness, the default `display: table` setup is often a pain to work with, so I can understand why people would opt for flexbox instead. One better option, though, might be to use `table` elements under the hood, styled with `display: grid` (and judicious use of subgrid for the intermediate elements) to get more precise control over the layout, while still using the right semantic elements underneath.
MrJohz commented on So you want to speak at software conferences?   dylanbeattie.net/2025/12/... · Posted by u/speckx
nrhrjrjrjtntbt · 7 days ago
What is the best way to show code?

I really want to show some code. Like 4-5 lines to give a gist.

MrJohz · 6 days ago
4-5 lines can be really effective. After all, if you're at a software conference, you're probably speaking to a bunch of programmers about programming, and code is your universal language.

But already 7-10 lines is stretching it, and any more than that, and it's a lot harder to get your point across because people spend so much time trying to parse the code sample.

The problem is that cutting down the code and coming up with an example that explains everything you want in just 4-5 lines is really hard — "if I had more time, I'd have written a shorter letter" and all that.

MrJohz commented on So you want to speak at software conferences?   dylanbeattie.net/2025/12/... · Posted by u/speckx
WalterBright · 7 days ago
> Powerpoint allows you all kinds of benefits like animations or transitions

I know. I just go for very basic stuff - large fonts, black text on white background, no border, no colors. I ruthlessly eliminate everything but the point I'm trying to make.

MrJohz · 6 days ago
Generally, I'm fully on board with the "eliminate everything but the point" philosophy, but transitions can be really useful for displaying that the same element is present in multiple slides. I've had a few cases where I've shown a "before" diagram/code sample/whatever, then on the next slide shown the same diagram again, alongside an "after" version. But the layout I use to put two diagrams on the screen is going to look different to the layout I use for just one, which means the original diagram is going to jump around suddenly.

A ~100ms transition where the first diagram moves from its place on the first slide to its place on the second slide ensures that a person looking at the slide understands very intuitively which of the two diagrams is the original, and which one has been added. It's not perfect (e.g. you'll miss it if you're not looking at the slides at the time), but for diagrams or code samples you generally want the audience to be focussing on the slides, so it typically works well. And in 90% of cases, even if you do miss it, it'll be obvious after a couple of moments' thought what's going on, but the transition saves you those couple of moments.

I could just show both items on the first slide, but I find it's often pedagogically useful to explore the initial state by itself, rather than jumping straight in with the comparison. That way you can motivate the comparison more clearly by identifying the issues with the initial state (be that a code sample, a diagram, whatever), before moving on to the comparison with a potential solution.

If it weren't for this one use-case, I'd probably also switch to PDFs, because I've been bitten by presentational issues before that would have been a lot easier to solve if the presentation had just been available as a PDF.

u/MrJohz

KarmaCake day2730February 14, 2022
About
https://jonathan-frere.com/

I write software and haven't come up with a great bio description yet.

View Original