Live data from Hacker News

Diminishing returns of static typing

blog.merovius.de

381–390 of 632 posts

Re: Diminishing returns of static typing

#381

Earlier quoted context omitted.

TXR Lisp, a dialect I created: $ txr This is the TXR Lisp interactive listener of TXR 185. Quit with :quit or Ctrl-D on empty line. Ctrl-X ? for cheatsheet. 1> (set a.b 3) ** warning: (expr-1:1) qref: symbol b isn't the name of a struct slot ** warning: (expr-1:1) unbound variable a ** (expr-1:1) unbound variable a ** during evaluation of form (slotset a 'b 3) ** ... an expansion of (set a.b 3) ** which is located at…

>There is dynamic and then there is crap dynamic. (...) There is crap static too. Excellent. My point exactly. I have no fear of using a static or dynamic language, as long as it is a good implementation of a statically (or dynamically) typed language.

What would you consider good implementations of either?

Re: Diminishing returns of static typing

#382

Earlier quoted context omitted.

I'm so happy to see the pendulum swing the other way, because when JavaScript was becoming popular, and Ruby and Python had a popularity renaissance (around mid to late 2000s), I had a lot of online arguments about the value of static typing. People were complaining about static typing for the dumbest reasons (it's too 'wordy'). It started as a backlash against old-school enterprise Java development (which was fair,…

>>There are a class of bugs you just never need to worry about when the compiler does some compile-time checks for you ... like worrying that you passed the wrong type into a function, or the wrong number of arguments. People always say this and it baffles me. Bugs like that should be caught immediately by your test cases. You shouldn't rely on the compiler to catch them for you.

Having a compiler catch this for you means having to write less test cases.

Re: Diminishing returns of static typing

#383
post #201
post #35

Earlier quoted context omitted.

I think dynamic typing proponents get hung up on the auto-complete aspect. The real benefit is when you find someone writing a property with a common-ish name to a data structure and you want to know "who the hell uses this", you can answer that question pretty easy in statically typed languages. In dynamically typed languages you kind of just grep and hope the name is not too common.

> In dynamically typed languages you kind of just grep and hope the name is not too common. For four days, I spent debugging a python production script because in one place I had typo'd ".recived=true" on an object and just couldn't understand why my state machine wouldn't work. And very quickly, the whole team became fans of __slots__ in Python. I still write 90% of my useful code in python, but that one week of deb…

That's a kind of error caught by the popular static analysis tools. Better add that pylint and mypy to your travis.yml as soon as possible.

Re: Diminishing returns of static typing

#384

Earlier quoted context omitted.

void * is part of it, but you can also implicitly cast from between integer types, and also between integers and enums. Think of passing an enum or an int into a function which takes a long as an argument.

I mean... I don't really think that's a strong case for calling C's type system weak.

I would say it's mostly a matter of use: In C you deal with void* or typecasts all the time, whereas in higher level languages it's much less common, either because the type system is smarter, or the constraints that it does have are more strictly enforced. For example: you can happily compare a char* and an int in C, but other languages like python might error at the thought.

Re: Diminishing returns of static typing

#385

Earlier quoted context omitted.

I mean... I don't really think that's a strong case for calling C's type system weak.

I suspect most people which state that C has a weak type system are really talking about the fact that C has a weakly _enforced_ type system. You can break the type system's rules rather easily (or perhaps it's more accurate to say, the type system is too permissive), either way it doesn't provide you the same guarantees a stronger type system provides). At least that's my take on it.

This.

Re: Diminishing returns of static typing

#386

Earlier quoted context omitted.

I mean... I don't really think that's a strong case for calling C's type system weak.

I would say it's mostly a matter of use: In C you deal with void* or typecasts all the time, whereas in higher level languages it's much less common, either because the type system is smarter, or the constraints that it does have are more strictly enforced. For example: you can happily compare a char* and an int in C, but other languages like python might error at the thought.

    /t/tmp.1q8r9dZAtX > cat test.c
    int main() {
    	char *test = "test";
    	int i = 10;
    	return test == i;
    }
    /t/tmp.1q8r9dZAtX > cc test.c
    test.c: In function ‘main’:
    test.c:4:14: warning: comparison between pointer and integer
      return test == i;
                  ^~

Re: Diminishing returns of static typing

#387
post #335

Earlier quoted context omitted.

> What exactly does it mean to have "good dynamic typing facilities"? To quote Peter Norvig on the difference between Python and Lisp, but you could apply it to most other mainstream dynamic languages vs Lisp : > Python is more dynamic, does less error-checking. In Python you won't get any warnings for undefined functions or fields, or wrong number of arguments passed to a function, or most anything else at load time…

What does “somewhat sound” mean?

I think he refers to some of the usual criticisms of Common Lisp:

1. The language specification is very big. This is true, it is a very big specification. On the other hand, this is mostly caused because the language spec also includes the spec for its own "standard library", unlike what happens in C or Java, for example, where the Std. lib is specified elsewhere. CL's "standard library" is very big, because there are many, many features.

The other reason the spec is so big, is that this is a language with a lot of features - you can do high level programming, low level, complex OOP, design-your-own OOP, bitwise manipulation, arbitrary precision arithmetic, dissasemble functions to machine language, redefine classes at runtime, etc etc etc.

Probably the extreme of the features is that there is a sql-like mini-programming language built in just for doing loops (!), "the LOOP macro". On the other hand, you can choose not to use it. And if you use it, it can help you write highly readable and concise code. More info:

http://cl-cookbook.sourceforge.net/loop.html

2. The "cruft"; Common Lisp is basically the unification ("common") of at least two main Lisp dialects that were in use during the 70s. So there are some parts (mind you, just some) in which some naming or function parameter orders could have been more consistent; for example here everything is consistent:

    ;; access a property list by property
    (getf plist property)

    ;; access an array by index
    (aref array index)

    ;; access an object's slot
    (slot-value object slot-name)
... but here the consistency is broken:

    ;; gethash: obtain the element from a hash table, by key
    (gethash key hash-table)
There is also sometimes some things that seem to be redundant, like for example "setq", where "setf" can do everything you can do with "setq" (and more); or for example "defparameter", and "defvar" where in theory "setf" might be enough. But there are differences, and knowing such differences help to write more readable and better code. And it's really nitpicking, for these are easy to overcome.

3. Because of the above, CL is often criticized because of being a language "designed by committee". But, unlike other "committee-designed languages", this one was designed by selecting, from older Lisps, features that were already proven to be a Good Thing, and incorporating them into CL without too many changes. So you can also consider it to be "a curated collection of good features from older Lisps..."

4. Scheme, the other main "Lisp dialect", has a much, much smaller and simpler spec, so it's easier to learn. But on the other hand this also means that many features are just absent, and will need to be implemented by the programmer (or by external libs), without any standarization. On the other hand, due to the extensive standarization, usually Common Lisp code is highly portable between implementations, and often code will run in various CL implementations, straight away, with zero change.

Historically, Scheme was more popular inside the academic community while Common Lisp was more popular with production systems (i.e. science, space, simulation, CAD/CAM, etc.) Thus, there used to be an animosity between Schemers and Lispers, although jumping from one language to other is rather easy...

Re: Diminishing returns of static typing

#389

Earlier quoted context omitted.

You can, but you may start to run into some limitations. Many languages have some version of type inference, which allows them to figure out the type of a thing, even though the programmer didn’t specify it. C# has a very weak version of this with the auto keyword. Languages like Crystal take it much further by tracing the flow of data through the entire program. It generally works quite well, though there are a few…

Type inference goes hand-in-hand with static typing. Those are not opposite things. > C# .... Crystal Both are fully statically typed languages with type inference. Those are unrelated to the argument the parent comment is making.

> Type inference goes hand-in-hand with static typing.

That would imply there's no type inference possible with dynamic languages - either at "compile" time or run time.

(Wouldn't it also imply that static typing and strong typing are synonymous?)

Re: Diminishing returns of static typing

#390

Earlier quoted context omitted.

It's Camp D that I'm least familiar with here; outside of academic projects in lisp/scheme I've never used them for anything serious. What exactly does it mean to have "good dynamic typing facilities"?

>What exactly does it mean to have "good dynamic typing facilities"? Picking Common Lisp as an example: (NOTE: Some of the features are also present in good statically typed languages as well, so what I advocate is to use good, well-featured languages, not really static vs dynamic.) (NOTE 2: I'm sorry for being such a fanboy, but that thing is addictive like a hard drug...) 0. Code is a first class citizen, and it ca…

> 3. The error handling system is exemplary: Not only designed to "catch" errors, but also to apply a potential correction and try running the function again. This is known as "condition and restarts", and sadly is not present in many programming languages.

I found this extremely weird and (or hence) interesting at the same time. Where can I read more about this?

Post reply on HN