Live data from Hacker News

The type system is a programmer's best friend

dusted.codes

411–420 of 467 posts

Re: The type system is a programmer's best friend

#411

Earlier quoted context omitted.

I’d take this further. I was listening to the John Carmack episode of Lex Fridman from the summer, and he makes a comment about being frustrated that in the Valley there’s an almost religious opposition to IDEs, debuggers, and static analysis. Some of those tools have only become more powerful over time and I’m perplexed as to the mindset that would make a person averse to automating the drudgiest parts of their job…

When I graduated college in the '00s I thought Vim was the most amazing thing I'd ever learned. Then a colleague at my first job showed me what happend when you typed . after a variable name in Visual Studio. Code completion, inline documentation...my mind was blown, and I never looked back. When I meet a young chap extolling the benefits of Vim or Emacs or really anything that doesn't have stepped debugging and code…

> there are no bonus points for doing things the hard way

Perhaps not from the technical perspective, but there are social advantages if you are a member of a clique that does things the hard way and considers it a sign of competence. ("Any idiot can write a code that compiles using autocomplete and syntax highlighting, but it takes a true master to achieve the same result using a decades-old Linux equivalent of Notepad.") They don't seem to understand that the ancient masters did things the hard way not as a pointless exercise, but simply because the easy way was not available back then.

Re: The type system is a programmer's best friend

#412

Earlier quoted context omitted.

Validating is just the process of ensuring an input is admissible in the way you want to use it. That can be symbols in a string, whether a string is an e-mail or even if a number is in a certain range. Escaping is just validation + fixup which can be used in some cases. Anyway the only way to validate an e-mail in practice is to use it and confirm.

> Escaping is just validation + fixup You're confused and annoyingly persistent. Escaping (or quoting in general) is a simple translation from a literal representation of a string to a (lexical) syntax representation with the purpose of embedding the string in an external medium (e.g. source code written in that lexical syntax). Escaping is a mechanical process that doesn't discriminate between "valid" and "invalid".…

> Escaping is a mechanical process that doesn't discriminate between "valid" and "invalid". It is completely ignorant to the higher-level meaning of the string that is translated (e.g. email address) but solely operates on the constituent characters.

It does discriminate between "valid" and "invalid". This symbol is "valid" and we don't need to do anything. This symbol is "invalid" and we need to escape it. Validation occurs throughout the whole abstraction stack. Not only at the level of meaning of an entire string.

> Which was my initial statement "Just use it" that you heavily disagreed with.

In the case of e-mail I don't disagree with you. It is however balls to the wall insane to say "Just use it" in general. Which was my point. Notice how my reply specifically mentions vulnerabilities that were caused by the "just use it" mantra.

Re: The type system is a programmer's best friend

#413
post #308

Earlier quoted context omitted.

> No, if your idea of validating an email is more complicated than "should have an @ symbol", I guarantee you, there is counter example that will mess you pretty system up. Requiring b2b users to use their @company.com email is common and some b2b customers actually expect to be able to configure that. Another simple case is stripping out any "+whatever" from gmail addresses and to flag that sort of thing for other e…

> Another simple case is stripping out any "+whatever" from gmail addresses and to flag that sort of thing for other eomains so support can verify it's not a case of someone creating 72 trial accounts. trial1@mypersonaldomain trial2@mypersonaldomain trial3@mypersonaldomain

But for that you need a personal domain and the ability to configure something like that, whereas everyone in a corporation that runs their email through Google can use the +abc thing out of the box, and I've seen it used a ton. The goal with measures like that is usually not to catch every single one who tries to game the free tier but to ensure it's more inconvenient to do so than just buy it for most people, and typically filtering +abc emails will be just one of several different measures taken to that end.

Re: The type system is a programmer's best friend

#414
post #308

Earlier quoted context omitted.

> Another simple case is stripping out any "+whatever" from gmail addresses and to flag that sort of thing for other eomains so support can verify it's not a case of someone creating 72 trial accounts. trial1@mypersonaldomain trial2@mypersonaldomain trial3@mypersonaldomain

But for that you need a personal domain and the ability to configure something like that, whereas everyone in a corporation that runs their email through Google can use the +abc thing out of the box, and I've seen it used a ton. The goal with measures like that is usually not to catch every single one who tries to game the free tier but to ensure it's more inconvenient to do so than just buy it for most people, and t…

There are sites where you can easily get all addresses of the format something@yourname.sitename.xxx.

Re: The type system is a programmer's best friend

#415
post #336

Earlier quoted context omitted.

that's the issue: there is no other way to create new types aside from creating a new class in mainstream languages. Those two concepts are separate, and should be treated as such. Types are not Classes, the last is just a lousy "embodiment" of the first

Classes are composite data types, what you are referring to are primitive data types. A class isn’t necessarily some wrapper around primitive types, they can contain data structures, other type instances, etc. Obviously that eventually leads to an end object containing a primitive, you can’t just have fancy trees of nothingness lol. https://en.wikipedia.org/wiki/Data_type#Classification_of_da...

Again, I was referring to user defined types (not primitive types), which are not classes.

Re: The type system is a programmer's best friend

#416
post #415

Earlier quoted context omitted.

Classes are composite data types, what you are referring to are primitive data types. A class isn’t necessarily some wrapper around primitive types, they can contain data structures, other type instances, etc. Obviously that eventually leads to an end object containing a primitive, you can’t just have fancy trees of nothingness lol. https://en.wikipedia.org/wiki/Data_type#Classification_of_da...

Again, I was referring to user defined types (not primitive types), which are not classes.

> A class specified by the keyword class, is a user defined type that contains both data members and member functions...

http://www.cs.fsu.edu/~cop3014p/lectures/ch8/index.html

Re: The type system is a programmer's best friend

#417

This is, IMvHO, such old news that it feels... weird to still read about it in a year with the prefix of 20. Every programmer who has ever single-handedly written a 100,000+ LOC software system will tell you the same thing: shift as much responsibility on the compiler as you can and have the compiler check the code you write to any extent technologically possible. Getting rid of bugs by experiencing, diagnosing and f…

While I also agree that static typing is the easiest, statically decidable way to significantly increase program correctness, I’m not sure we can do significantly better with it then we currently do. Most interesting properties are not expressible even with dependent types, and those are very hard to prove, making their advantages non-no-brainers.

What I’m trying to say is that we should be open about another concept, for example contract-based programs (clojure’s spec for example), because they might have better properties.

Re: The type system is a programmer's best friend

#418
post #323

Earlier quoted context omitted.

If you actually pay attention to the “a whole bunch of stuff”, maybe you'll understand the latter statement.

That's not possible, because I can't discern the final cause of all these theorems and definitions in "a whole bunch of stuff". It all comes off as a game of defining abstract objects just for their own sake.

A good teacher should explain why the definitions and theorems are useful. I'm sorry you've had a bad experience.

Re: The type system is a programmer's best friend

#419

Earlier quoted context omitted.

> Escaping is just validation + fixup You're confused and annoyingly persistent. Escaping (or quoting in general) is a simple translation from a literal representation of a string to a (lexical) syntax representation with the purpose of embedding the string in an external medium (e.g. source code written in that lexical syntax). Escaping is a mechanical process that doesn't discriminate between "valid" and "invalid".…

> Escaping is a mechanical process that doesn't discriminate between "valid" and "invalid". It is completely ignorant to the higher-level meaning of the string that is translated (e.g. email address) but solely operates on the constituent characters. It does discriminate between "valid" and "invalid". This symbol is "valid" and we don't need to do anything. This symbol is "invalid" and we need to escape it. Validatio…

> This symbol is "valid" and we don't need to do anything. This symbol is "invalid" and we need to escape it.

It's quite a stretch to call symbols that need to be escaped “invalid”. And it's often possible to escape without discerning between “valid” and “invalid” characters. For example, in HTML you might just convert all characters into numeric entities.

> It is however balls to the wall insane to say "Just use it" in general.

Good thing the parent didn't say it in general.

Re: The type system is a programmer's best friend

#420

Earlier quoted context omitted.

But there's a paradox. Why does 100,000 lines of code of python tend to be safer and more manageable then 100,000 lines of C++ despite the fact that python has no type checker and C++ has a relatively advanced type checker? Why do startups choose a python web stack over a C++ web stack? I don't think it's "self-evident." I think there's something more nuanced going on here. Hear me out. I think type systems are GREAT…

You shouldn't compare a Python web stack with a C++ web stack, as C++ and Python target very different use cases. You can compare however with a Java or C# web stack, both of which offer a superior developer experience, as well as a superior production experience (monitoring, performance, package management, etc.).

The comparison isn't happening because everyone is getting caught up in some language war.

I compare C++ and python because I'm trying to make a statement about types. How types are actually not as important as people think.

C++ and python are good examples because python is safer and easier to use then C++ yet python doesn't have type checking.

Post reply on HN