You are viewing archived messages.
Go here to search the history.

Paul Tarvydas 2024-03-26 02:27:50

At about 54:20+, Crockford ends up saying that types cause bugs. What are examples of those kinds of bugs?

youtube.com/watch?v=XFTOG895C7c

Duncan Cragg 2024-03-26 11:17:42

I think he's saying that having to bend your thoughts to suit or evade the type system causes the really tricky bugs because your natural train of thought or expectations have been disrupted.

Duncan Cragg 2024-03-26 11:20:08

Which I agree with.

Duncan Cragg 2024-03-26 11:34:56

I would have to go away and ponder good examples, but it'll be something around edge cases where a strict type doesn't capture the domain type

Paul Tarvydas 2024-03-26 12:24:12

I agree. EEs use (or used to use when I learned how to design electronics) a concept more powerful than "types". It was called "design rules". You could specify - on a per project basis (instead of generalizing) - some rules / invariants that had to be upheld. For example "don't let parallel lines on a printed circuit board be longer than XX inches, (since long lines in parallel can cause noticeable cross-talk and this circuit is designed to tolerate only YYmicro-volts of cross-talk)", or, "this project uses ECL chips, ensure that lines on the PC are equal in length (since the speed of light begins to matter and some signals might arrive before others)", etc. It seems to me that "dependent types" are a step in the direction of writing more-flexible programs about types (rather than writing programs about values in memory), which basically admits that most general purpose programming languages aren't really all that general (you get what the language designer thought was important, instead of what your project says is important)

Ionuț G. Stan 2024-03-26 15:29:37

I fail to remember any situation in which I had a bug caused by a type system... The only way I can interpret his statement is that a type system might give you a false sense of safety (I never agreed to the Haskell mantra that if it compiles, then it must be correct, although it can and does happen), so you can then neglect test coverage.

More often than not the adamancy of a type system to accept my code forced me to become aware of intricacies in the domain model. Is it perfect? Nope, nothing is, but it's more helpful for me to use a tool with a type system.

I think Crockford sometimes makes some unwarranted assertions. He used to say that parsing JSON was the only acceptable use of eval in JavaScript, which I never understood, since one should absolutely not use eval on external input.

Fredrik 2024-03-26 20:04:30

He seems to be in favor of duck typing, and if the type system prevents you from making a solution that relies on duck typing, he assumes that your alternative solution will be more complicated and have a higher risk of defects, which is an unproven assumption just like all his other opinions. He could equally well have made the opposite claim, that the type system forces you to make a cleaner solution that other programmers can understand without finding surprises, but what opinion he chooses to go with on each question seems to be a roll of dice.

Duncan Cragg 2024-03-26 20:11:15

If more of us loose/dynamic typing advocates rock up this could turn into a vim/emacs bunfight!

Fredrik 2024-03-26 20:31:52

That's what the JS community loves to do, and Douglas opens with a bunch of slides making strawmen arguments telling that anyone who disagrees with him is stupid and has no facts to come with. In fact, both Vim and Emacs are severely outdated, and I'd rather have the future of editors and programming than influencers provocing flamewars about binary choices of features from the past, as if these features are the ultimate and one of them must be the winner.

Duncan Cragg 2024-03-26 20:58:02

Been usin' vi(m) 44 years, man-n-boy, an' I ain't stoppin' now. Pfwah! You young 'uns!

Dave Liepmann 2024-03-27 10:54:02

It's not strictly an example of a bug but Crockford wrote a bit about his thinking in How JavaScript Works:

Types are not blamed for the bugs they fail to find, the expensive bugs. And types do not get blamed for the problems they cause by requiring circumvention. Types can induce us to embrace cryptic, intricate, and dubious coding practices.

An example he gives elsewhere of such circumvention:

The Java language encourages misuse of exceptions as a way to get around problems in its type system. A Java method can only return a single type of result, so exceptions are used as an alternate channel to return the ordinary results that the type system does not allow.

The paper Well-Typed Programs Can Go Wrong: A Study of Typing-Related Bugs in JVM Compilers has some concrete bugs caused by types:

In statically-typed programming languages with rich and expressive type systems and modern features, such as type inference or a mix of object-oriented with functional programming features, the process of static typing in compiler front-ends is complicated by a high-density of bugs. Such bugs can lead to the acceptance of incorrect programs (breaking code portability or the type system’s soundness), the rejection of correct (e.g. well-typed) programs, and the reporting of misleading errors and warnings.

Screenshot 2024-03-27 at 11.53.00.png

Ionuț G. Stan 2024-03-27 11:15:02

😂 Typical Crockford:

The word for 1 is misspelled. I use the corrected spelling wun . The pronunciation of one does not conform to any of the standard or special rules of English pronunciation. And having the word for 1 start with the letter that looks like 0 is a bug.

That actually kinda puts in perspective all the other stuff, honestly.

Fredrik 2024-03-28 06:59:28

The Java language encourages misuse of exceptions

That makes sense. I'm getting the feeling Douglas makes a sweeping generalization based on his knowledge of Java, which does not have a helpful type system. It shows ignorance to Typescript, which the question was actually about, and even more ignorance to more advanced type systems, such as that of Rust that prevents bugs by having a good way to handle errors instead of relying on exceptions, and also unlike Typescript prevent mixing up two different things that happen to have the same shape.

I find it contradictory to claim that type systems are not helpful and in the same presentation preach the use of Eslint. Eslint can't do its job well, because it doesn't know the intended type of values, so it mostly does low value remarks that don't help prevent bugs. I consider objects to be one of the bad parts of JS, because Eslint can't detect invalid property accesses, so I don't do objects, and instead pass everything through closure variables that Eslint can check.

Fredrik 2024-03-28 07:33:52

That actually kinda puts in perspective all the other stuff

Jes, é pörspektiv ov kaming ap with wan naív ajdía withaut síing the kontext énd thinking hí's rajt abaut it énd evrywan els is wrong. Ingliš has no konsistent speling, énd the wörd wan is nou eksepšön. Wí kud sí the big piktšör énd rífórm the houl lénggwitš, énd thät stil dásn't wörk, becós íngliš hes tú méni démn homofouns.

Dave Liepmann 2024-03-28 08:38:00

I find it contradictory to claim that type systems are not helpful and in the same presentation preach the use of Eslint.

Does JSLint (which he recommends at 5:35) incur the same costs of type systems (circumvention, cryptic or complex code patterns) which bother Crockford? To me it seems not, thus no contradiction. He uses the tool to block off parts of the language he considers foot-guns, and to "increase the visual distance between a good program and a bad one". These goals seem distant to those of type systems.

Fredrik 2024-03-28 09:16:31

@Dave Liepmann I guess he's bothered by completely different things than other programmers then.

Ionuț G. Stan 2024-03-28 09:38:28

[offtopic: For a split second, @Fredrik, my brain wanted to put that through Google Translate because it looked like Czech or Slovak or Polish, something in that linguistic area 😅]

William Taysom 2024-03-29 13:48:45

@Fredrik it's funny that Chat does a good job normalizing your funny message's spelling. (Only added "one is now no exception.") Homophones are one reason why Pinyin was not adopted during twentieth century attempts to simply Chinese characters.

Justin Janes 2024-03-29 02:18:31

Does anyone have any solid papers on interactions with operating systems using primarily hand gestures from cameras and projectors? I know this is very dynamicland but i’m kinda tired of waiting for a system i can let the kids play with on the carpet.

Joshua Horowitz 2024-03-29 02:36:28

it’s not a paper (& may or may not be “interactions with operating systems”?) but: folk.computer

Joshua Horowitz 2024-03-29 09:38:51

oh it's also not hand gestures! sorry I didn't notice that part.

William Taysom 2024-03-30 10:10:48

My sister asked whether her middle-school son should pick the choice of a block programming language (like Scratch), JavaScript, or C# for a class he's in. I claimed that he'll learn the same fundamentals with blocks minus the frustration, tedium, tea ceremony, and incantations associated with the others. To prove that the block program has the real creativity and that moving to the others is practically automatable, I took may favorite Scratch program scratch.mit.edu/projects/605658 and had Chat translate it into JavaScript and C# chat.openai.com/share/02215935-c0b8-4fc9-9bf9-94f0b3fab613. The results seemed promising. Chat even made helpful observations:

Translating the same Scratch program to C# requires a different approach because C# is often used in desktop applications, and there's no direct equivalent of the Canvas API like in web technologies. However, you can use Windows Forms or WPF (Windows Presentation Foundation) for graphical applications in C#. Here, I'll provide an example using Windows Forms to create a simple drawing application that mimics the Scratch program's behavior.

If you check my conversation, you'll see I start asking what a "partial class" is having never heard the term. Chat parroted:

Using partial classes in this way provides flexibility. You can start with all your code in one file for simplicity. Then, if the class grows or you decide to use the designer, you can easily refactor the designer-generated code into its own file without changing the class's functionality. This approach keeps your custom code separate from the auto-generated code, making it easier to read and maintain.

I explained that every language, every tool has many such conventions. You learn the ones reverent to whatever you're doing right now, but learning them all is impossible. Instead the real skill is knowing that you don't know and being able to find out quickly. We're lucky that a these things are obscure, come up often, and are discussed on the Web. Thus LLMs are especially good at helping with dumb programming problems.

So why use the established languages besides Chat knowing them well? I thought of three reasons:

  • Expressivity — Blocks will get a beginner pretty far, but you'll find the others have constructs that helpful for saying things that would be very hard with blocks. You won't appreciate scratch until you feel the itch.
  • Causal Powers — The block system will let you do things in class you'll learn core ideas, but the blocks themselves won't work everywhere. JavaScript, on the other hand, works all over on the web, and C# has its own ecosystem. Often there's bridging, but also one or other language will be the most natural one for certain kinds of work.
  • Scale — With big and medium sized programs being done with text, editors for wrangling it, and version control for keeping track of it exist. They can we weirdly powerful and janky. But you're liable to start having a hard time keeping track of blocks when it takes a dozen or more screens to fit them all.
Christopher Shank 2024-03-31 17:14:19

I think there is a project that explores that translation x.com/moenig/status/1601890041499996161?s=20

🐦 Jens Mönig (@moenig) on X: Did you know that since a decade ago Snap! can translate blocks to any textual grammar? I’m now experimenting with backmapping arbitrary grammars to identify blocks from text code. Just now went live on a line-of-code basis: https://t.co/lLMGD1c1dY

Tweet Thumbnail

🕰️ 2024-03-09 10:29:03

...

Kongwei Ying 2024-03-31 09:48:01

Jim Meyer I'm working on something a bit like what you're talking about. The biggest problem I see at the moment is that the best programmers (and AI to a large extent these days) have developed a meta cognitive layer over plain textual code, that more accurately describes the data structures and flows of information inherent in code.

Simplest example is assignment

let fruit = "banana"

The implicit flow is

"banana" -> fruit

"banana" is also a constant, whereas the variable fruit, is a store of information that may change over time.

So how to visually represent that fruit is possibly changing, and is a store of information, and that the string "banana" is constant, beyond the obvious string marks and let declaration?

We could show a flowing string of information that goes from "banana" to the variable fruit. Fruit could be highlighted with water as a background, and "banana" could be highlighted with concrete as a background. Maybe this isn't the best visual representation but you get what I mean.

Obviously it gets way more complicated than simple variable declarations and variable assignment but imagine if this kind of visual representation was extended to almost every single aspect of the language?

If, we could explicitly show this implicit meta cognitive layer as visually overlaid over the text itself, it would be a revolution for newbies and seasoned veterans. For newbies, they would understand the logic and flow of the code much much faster, and for veterans, their brain power would be freed from trying to visualise this meta cognitive structure, to focusing on even higher abstraction problems.

The main problems I see are:

  • Identifying all the implicit structures inside our programming languages
  • Creating an intuitive visual representation of each, that is easily understandable
Kongwei Ying 2024-03-31 09:48:01

Jim Meyer I'm working on something a bit like what you're talking about. The biggest problem I see at the moment is that the best programmers (and AI to a large extent these days) have developed a meta cognitive layer over plain textual code, that more accurately describes the data structures and flows of information inherent in code.

Simplest example is assignment

let fruit = "banana"

The implicit flow is

"banana" -> fruit

"banana" is also a constant, whereas the variable fruit, is a store of information that may change over time.

So how to visually represent that fruit is possibly changing, and is a store of information, and that the string "banana" is constant, beyond the obvious string marks and let declaration?

We could show a flowing string of information that goes from "banana" to the variable fruit. Fruit could be highlighted with water as a background, and "banana" could be highlighted with concrete as a background. Maybe this isn't the best visual representation but you get what I mean.

Obviously it gets way more complicated than simple variable declarations and variable assignment but imagine if this kind of visual representation was extended to almost every single aspect of the language?

If, we could explicitly show this implicit meta cognitive layer as visually overlaid over the text itself, it would be a revolution for newbies and seasoned veterans. For newbies, they would understand the logic and flow of the code much much faster, and for veterans, their brain power would be freed from trying to visualise this meta cognitive structure, to focusing on even higher abstraction problems.

The main problems I see are:

  • Identifying all the implicit structures inside our programming languages
  • Creating an intuitive visual representation of each, that is easily understandable