News for hackers. Stuff that matters.
Re:38% of bugs at Airbnb could have been prevented by using ... by Mirioron on Monday February 11, 2019 @02:36AM (#19132664)
I've never really understood the advantage of dynamic typing. Not having to specify type to me seems like it's barely an advantage and immediately gets outweighed by the fact that you don't have compile time type checking (or have to jump through hoops to get it).

Typing out code tends to be a minor part of writing software, so you don't gain much there. Furthermore, you don't want to mix types in the same variables either, because this comes at a cost of performance and complexity.

So, what kind of flexibility do you get from dynamic typing?

Re:38% of bugs at Airbnb could have been prevented by using ... by mattmanser on Monday February 11, 2019 @04:34AM (#19133129)
As someone who is very pro-static typing, the big annoyance for me is that sometimes you have to write a load of boilerplate purely because of the type system.

It's got a lot better in the last decade, but with the more advanced features of a language you can find yourself slowed down in a few ways. Maybe by having to explicitly declare types where you'd normally implicitly declare them. Or you might have a load of methods that actually throw 'Not Implemented' errors because you are forced to match a massive interface but it only has to do one thing (yes, C# has an actual NotImplemented exception because this is so common).

It's annoying and can interrupt your flow, mean you have to spend a bit of time searching for the right voodoo code to make it work or you sometimes feel like you're doing a rain dance just because of the type system.

The other thing is that you're sometimes forced to cast a variable to a type that you know is already that type, but a method has returned it as an 'object'. It feels really clunky, e.g. event listeners.

Re:38% of bugs at Airbnb could have been prevented by using ... by koyote on Monday February 11, 2019 @04:50AM (#19133196)
I'm playing a bit of devil's advocate here, but:

> Or you might have a load of methods that actually throw 'Not Implemented' errors because you are forced to match a massive interface but it only has to do one thing (yes, C# has an actual NotImplemented exception because this is so common).

I would heavily argue that if you encounter such a scenario you are probably Doing It Wrong® or you were unfortunate enough to inherit/have to work with some badly designed code.

Re:38% of bugs at Airbnb could have been prevented by using ... by mattmanser on Tuesday February 12, 2019 @02:05PM (#19146428)
In an ideal world maybe, but there's no point fully fleshing out an interface where you know you're not using those methods. I'm old enough and ugly enough to comprehensively know what I'm doing.

It's simply because interfaces in a framework are occasionally quite big and unwieldy, I'm sure their developer thought it was for good reasons, the other option is to split the interface up and have a class inherit from a ton of interfaces, which is just as annoying.

There's a few other replies here I'm rolling my eyes at because real-world programming is messy and being too dogmatic with ideals simply isn't practical.

Re:38% of bugs at Airbnb could have been prevented by using ... by regularfry on Monday February 11, 2019 @05:36AM (#19133418)
Then you run into the problem of the massive global framework having Done It Wrong and not being able to deprecate.

(note: this is not unique to static type systems)

Re:38% of bugs at Airbnb could have been prevented by using ... by dorgo on Monday February 11, 2019 @05:48AM (#19133485)
Yes, but even Java standard libraries throw UnsupportedOperationExceptions. It is so sad.

Edit: This is exactly the point where a type system betrayes its promises.

Re:38% of bugs at Airbnb could have been prevented by using ... by twic on Monday February 11, 2019 @10:36AM (#19135142)
So try and avoid it, like Scala - you have now found yourselves trapped in an incomprehensible maze of GenTraversable and the like.
Re:38% of bugs at Airbnb could have been prevented by using ... by scarface74 on Monday February 11, 2019 @06:02AM (#19133549)
Or you might have a load of methods that actually throw 'Not Implemented' errors because you are forced to match a massive interface but it only has to do one thing (yes, C# has an actual NotImplemented exception because this is so common).

That’s where the “I” in SOLID comes in.

Re:38% of bugs at Airbnb could have been prevented by using ... by marcosdumay on Monday February 11, 2019 @06:24AM (#19133645)
Hum... I think it was upper on this thread that some GP was preemptively excusing the people hurt by Java. Well, C# is the same.
Re:38% of bugs at Airbnb could have been prevented by using ... by zozbot123 on Monday February 11, 2019 @06:26AM (#19133652)
> Or you might have a load of methods that actually throw 'Not Implemented' errors because you are forced to match a massive interface but it only has to do one thing ... The other thing is that you're sometimes forced to cast a variable to a type that you know is already that type, but a method has returned it as an 'object'. It feels really clunky

These are not "problems with static typing", though. Dynamically-typed languages have you do these things all the time, it's just that you don't even notice it anymore because it's so common and you don't have static types as an alternative there.

Re:38% of bugs at Airbnb could have been prevented by using ... by scarface74 on Monday February 11, 2019 @06:00AM (#19133539)
I’ve hated dynamic typed scripting languages for over two decades and could never understand why anyone could possibly advocate for them. But, I was “forced” to learn Python within the last year and it was also my first time doing any type of automation, mostly with AWS. Before then, I only did “real programming”.

I have to admit for short programs without a lot of business logic where you are just providing a little glue - ie every time a csv file hits S3 run this lambda that executes a sql script to import it into a Redshift (OLAP) database, transform it with some queries, export the results back into S3, import it into Aurora (Mysql) and then load it into this appropriate tables - Python is my go to language out of the three “approved” languages (c# and JS being the other two).

I still don’t know why I like Python but hated Perl and PHP. But, I do know why and when I reach for Python over C#.

- when I know that more than one developer won’t be working on the same code and you don’t need the benefit of strong typing to help ensure that changing the signature one place won’t effect code somewhere else.

- Little conditional business logic. When you can easily gain complete code coverage just by running the script.

- small program that I can easily reason about.

- in the case of AWS and lambda, you can edit and test code right in the browser for both Python and JS. If you don’t need anything but the AWS SDK (Boto3), there is nothing to package. Once you get your code right, you copy and paste your code from the AWS consuls, export your configuration as a CloudFormation snippet and create your CI/CD pipeline.

It’s also easier to debug directly on the server without having to either have a compiler on the server or trying to set up remote debugging.

Until about a month ago, I had only written a REST API in C#. I wrote my first service in Node/Express just because I wanted to be one of the cool kids. I hated every second of not having a strongly typed language especially with my JSON objects. The tooling by definition can’t be as good especially for refactoring. Yeah I know about Typescript and I’ve played with it. I didn’t want to go down that rabbit hole and try to get buy in from the company.

On a side note. I’ve used Mongo before but only with C#. With the C# Mongo LINQ driver, you are working with strongly typed collections and strongly typed LINQ queries. I can’t imagine the hellish landscape of using a weakly typed language and a weakly typed data store.

Re:38% of bugs at Airbnb could have been prevented by using ... by wutbrodo on Monday February 11, 2019 @03:53AM (#19132958)
So I probably agree with you more than you think, but I'm trying to tilt the scales towards dynamic typing a little to counteract any bias I may have from the fact that all my work with static typing has been with talented engineers and all my work with dynamic typing has been with garbage ones.

I agree with you about there being no concrete advantage to not being forced to specify the type of something; honestly, I don't even like type inference in eg C++ all that much, except as syntactic sugar over really ugly template types for whom the type just pollutes the code without adding any signal. But for example, I don't even really see the advantage of using auto in:

for (Widget widget : widgets) {

That being said, I do believe there is a concrete flexibility advantage, that I pray you never need to take advantage of but that sometimes can't be avoided in seed-stage startups. There were a couple of times where I monkey-patched the definition of a function (including an external library once! Oh the shame...) in order to get something working for a sales demo, and we just wouldn't have had the velocity to take shortcuts like that in a language like Java or C++, though I would personally make the fixing of the hack a P0 or at least a P1. These kind of "intentional bugs" allow you a bit more flexibility with using tech debt, and in the hands of skilled enough engineers, can provide you with boosts of velocity when you need it in the short term (at the cost of overall velocity).

Similarly, some pretty nifty stuff in libraries is possible due to the flexibility of these languages. I'm not a huge fan of frameworks in general, but my understanding of Django's ORM is that it compares quite favorably to ORMs in other languages. Given the amount of times I needed to do database surgery on prod (did I mention how much this company sucked?), it was a lifesaver to 1) have such an expressive interface to the DB and 2) have both an interpreter in the same language as our code and the ability to import and run production code. I'd imagine that pretty much every part of this would be more difficult in a less permissive language.

Re:38% of bugs at Airbnb could have been prevented by using ... by scarface74 on Monday February 11, 2019 @06:07AM (#19133570)
I’m just started to get into Python and I generally don’t see the point of ORMs since they really don’t add much in my opinion. I’m really curious about Why you like the ORM for Python.

The only ORMs I’ve ever found useful are those based on LINQ because LINQ makes any ORM (and whatever you call the Mongo LINQ driver) first class citizen and it integrates into the language.

Re:38% of bugs at Airbnb could have been prevented by using ... by wutbrodo on Monday February 11, 2019 @02:41PM (#19137553)
I have the same rough opinion of ORMs in general and I've never had the occasion to examine it: it was the right choice for our org because there's no way in hell the engineers were going to learn to write good SQL when they could barely write good Python, especially when I'm far from a SQL expert. I was at the time capable of writing good SQL (presumably after a ramp up period), but I doubt my capability to teach it well without significant time investment. The ORM was a path of least resistance thing, providing a simple, easily-comprehensible interface in the language they were already writing.

In the specific context of stuff-is-on-fire, production database changes (I'll reiterate, this place sucked), the fluency of the ORM and its seamlessness with our code was helpful. I don't know much about LINQ, but I gather that the syntax is declarative, which is a perhaps-minor speedbump that would nevertheless have made me less fluent in the specific above-described scenario.

In the general case of engineering, LINQ looks like something I would far prefer.

This isn't a criticism of your comment or anyone else's, but I have to say I'm amused by how all of my responses downthread of my comment are in defense of me being charitable towards more permissive languages (as I said, my bias probably swings solidly the other way, and if I never engineer in a permissive language again, I'll die happy). I kind of assumed it would go the other way, with HN jumping on my comment as elitist or something.

Re:38% of bugs at Airbnb could have been prevented by using ... by scarface74 on Monday February 11, 2019 @05:36PM (#19139127)
Every other ORM is bolted on.

For instance if you write the following using LINQ:

var x = from c in customers where c.Age > 65 && c.Sex == “male” select c;

var results = x.ToList():

If customer represents an in memory list, it gets translated as regular old compiled code.

If customer represents a sql database table - it gets translated to SQL and run on the database server.

If customer represents a Mongo collection. It gets translated to a Mongo query.

Of course you can do stuff like switch out what customer represents at runtime and it will be translated appropriately. You also get autocomplete help and compile time type checking.

You can pass the where clause around:

var expression = c.Age > 65;

And pass it into a method.

Re:38% of bugs at Airbnb could have been prevented by using ... by zozbot123 on Monday February 11, 2019 @06:33AM (#19133674)
> Similarly, some pretty nifty stuff in libraries is possible due to the flexibility of these languages.

You pay for that "flexibility" quite directly in lack of verifiability and of adequate performance. It's not a free lunch - if it was, we would all be using LISP anyway.

Re:38% of bugs at Airbnb could have been prevented by using ... by brlewis on Monday February 11, 2019 @08:13AM (#19134175)
If those were the reasons for LISP's lack of popularity, then LISP would have been more popular than Python or PHP.

What happened is that 1980s hardware was not ready for languages slower than C. C became the dominant language, and C-style syntax became the dominant syntax, with C++, Java and JavaScript following its lead. Eventually people adopted languages slower than C, but they didn't adopt paren-prefix notation.

Re:38% of bugs at Airbnb could have been prevented by using ... by kazinator on Monday February 11, 2019 @06:01PM (#19139356)
People used slower-than-C languages throughout the 1980's and onward: for instance BASIC-s (eventually Microsoft's Visual Basic starting in 1991), Ashton-Tate's dBase and its derivatives ("xBase").
Re:38% of bugs at Airbnb could have been prevented by using ... by wutbrodo on Monday February 11, 2019 @02:46PM (#19137606)
Yes, I didn't say it was a free lunch. The entirety of my comments here are about how there are pros and cons to every language that manifest in different situations, and things like "ability to go into ugly technical debt for short-term speed boost" being a pro has nothing to do with the claim that it's an unalloyed good, but there are situations that play to its strengths and weaknesses. I hate to be rude, but I'm really not sure how you thought I hadn't already made this point if you had read the thread we're on. If anything, my original comment comes close to saying that static typing is superior, period (though the same caveats apply about different situations requiring different sets of strength and weaknesses).

The obvious example here is that I unquestionably do my personal scripting in Python instead of C++, despite very much enjoying engineering jobs in the latter to those in the former. Different situations, different requirements.

Re:38% of bugs at Airbnb could have been prevented by using ... by paganel on Monday February 11, 2019 @07:28AM (#19133907)
> I've never really understood the advantage of dynamic typing.

It's easier to write code in dynamic-typed languages because (generally speaking, I'm pretty sure there are exceptions to this rule) dynamically-typed languages are not as verbose as static-typed languages.

The focus is now on writing bug-free programs as best as we can, but I remember that when I started programming about 15 years ago there was still a vibe of "let's make it as easier as possible for people to program so that everyone can write code, bugs don't matter (at least not that much)". That was the general vibe behind HTML and browsers (the way that you can see the actual HTML "code" that displays this very page, even if it may be "broken" HTML), behind early JavaScript (anyone remembers how one was able to include different JS-widgets on one one's HTML page?) and behind very cool projects like One Laptop per Child [1] (which got killed by Intel and MS among others and which, presumably, was allowing its users to see the Python source-code of each program they were using). Those were the dying times (even though I didn't know that at the time) of "worse is better".

But in the meantime the general feeling around writing computer programs has changed, correctness and "bug-free-ness" are now seen as one of the main mantras of being a programmer, and the programming profession itself has built quite a few walls around it (TDD was the first one, "use static types or you're not a real programmer" seems to be the latest one) so that the general populace can be kept at the gates of the "programming profession". In a way that suits me, because I'm a programmer and less people practicing this profession means more potential guaranteed earnings for me, but the idealist in me that at one moment thought that programming could (and should) become as widespread as reading stuff like books and newspapers feels let down by these industry trends.

[1] https://en.wikipedia.org/wiki/One_Laptop_per_Child

Re:38% of bugs at Airbnb could have been prevented by using ... by leshow on Monday February 11, 2019 @12:09PM (#19136009)
> It's easier to write code in dynamic-typed languages because (generally speaking, I'm pretty sure there are exceptions to this rule) dynamically-typed languages are not as verbose as static-typed languages.

I really don't understand this argument. What typed languages have you used?

Decent type system are able to infer most or all of your types. Meaning you ge the benefits of a type system without having to explicitly type everything.

Also, when you code, is your bottleneck serious how fast you can type? If it is, I would suggest you need a different approach.

> But in the meantime the general feeling around writing computer programs has changed, correctness and "bug-free-ness" are now seen as one of the main mantras of being a programmer

We are engineers, or at least we should be. Correctness has to be a goal, although I feel like even saying that is laughable right now. The amount of effort to prove a program is correct is extremely high for anything nontrivial. Robust type systems at least help cover our bases and help us reason about the structure of things, and more powerful type systems allow you to push even more invariants to the type system.

Re:38% of bugs at Airbnb could have been prevented by using ... by paganel on Monday February 11, 2019 @01:15PM (#19136677)
> Also, when you code, is your bottleneck serious how fast you can type? If it is, I would suggest you need a different approach.

My brain can process only so much information, the less thing it has to process (like the less type declarations) the better.

> We are engineers, or at least we should be. Correctness has to be a goal, although I feel like even saying that is laughable right now.

That’s what I was trying to explain, in a very convoluted way, that back in the day programmers were not intrinsically viewed as engineers, and that that viewpoint was seen as a valid one. Engineers were seen as building cathedrals while programmers (or hackers, if you will) were seen as building bazaars and other random stuff (like forums written in Lisp-like languages like Arc).

Re:38% of bugs at Airbnb could have been prevented by using ... by leshow on Tuesday February 12, 2019 @09:53AM (#19143898)
> My brain can process only so much information, the less thing it has to process (like the less type declarations) the better.

Ignoring that I've already mentioned inference that makes this a non-issue. My other problem with this is that just because you don't have a type system or don't have to write types, doesn't mean that the constraints of that 'information' goes away.

Your function still has a set of invariants that need to be maintained, you've just opted to make them invisible and have your program crash when they are violated. Instead of knowing statically when you've made a mistake.

Re:38% of bugs at Airbnb could have been prevented by using ... by Mirioron on Monday February 11, 2019 @08:06AM (#19134128)
>It's easier to write code in dynamic-typed languages because (generally speaking, I'm pretty sure there are exceptions to this rule) dynamically-typed languages are not as verbose as static-typed languages.

I don't understand this reasoning though. Actually typing out the code takes a fraction of the time that you spend on writing software. Furthermore, we have autocomplete and had autocomplete for a long time in statically typed languages.

I was formally taught programming about a decade ago in Python, but I naturally gravitated towards Java (and C) because of static typing. The same arguments were made back then and I just didn't get them.

Re:38% of bugs at Airbnb could have been prevented by using ... by wutbrodo on Monday February 11, 2019 @08:05PM (#19140107)
As my comment near the top of this comment tree hinted, I pretty much do find statically-typed languages to be overall quite superior, but the reason that I find myself defending dynamically-typed languages all over this thread is because of the hard-line being taken by many that they couldn't possibly have any advantages in any situation. I do plenty of scripting, to improve both my personal and professional productivity, and I don't even think twice about using Python instead of Kotlin or C++ or what-have-you. I iterate rapidly on my scripts, they're not part of large engineering systems that a reader may be bouncing around, the rare bug that may pop up isn't production-critical, and the ability to be both fluent and concise just makes the code faster to read and write, given the small scope of the program. This is sort of a lazy example, because it's not far from the truth to say that scripting languages are suited to scripting and that's why they suck for engineering, but it illustrates the point that different situations can highlight or downplay the importance of the relative strengths of weaknesses of various languages and paradigms, and there are few common programming-language characteristics[1].

The problem here is that half the people on this thread are looking for a simple, low-dimensional model to cram the issue into, requiring dynamic languages to have _zero_ advantages in order to sustain their view that statically-typed languages are superior overall.

I'm not really sure how to fix this tendency, and it's by no means limited to just disputes within the field of programming, Simpler, black-and-white models are much easier for the brain to handle, so people gravitate towards them even when they don't match reality as accurately.

[1] though it is fair to say that a big chunk of the advantage of dynamically-typed languages is "accessibility to those who barely know how to code", which doesn't affect the calculus for someone who's capable of writing in either type of language

Re:38% of bugs at Airbnb could have been prevented by using ... by victorNicollet on Monday February 11, 2019 @01:02PM (#19136548)
The problem is not that it takes a while, but that it takes a while when I'm in the middle of a complex task. Because of language verbosity, I might need to context-switch away from solving a hard problem.

For instance, if I am writing a complex function `frobnicate(x)` and I notice that I need to pass a configuration object to the function, I can just `frobnicate(x, opts)` in the function declaration, and `x.foo` to access the relevant option, and go back to the complexity that is still fresh in my mind.

With a verbose type system, I need to pick a type for `opts` NOW, which means I need to define a new type NOW, which will typicaly involve a new file with at least a dozen lines. By the time I'm done generating those stubs, the hard bits of the original function will have faded from my mind.

The code I write, in either case, isn't the final code. Once I have an initial working version where the complexity has been embedded in actual code instead of floating around in my mind, I can start iterating, refactoring, annotating, and so on. In TypeScript, at this point I will define a new options type and annotate `opts` with it.

Re:38% of bugs at Airbnb could have been prevented by using ... by chousuke on Monday February 11, 2019 @03:05PM (#19137747)
Or you could just not. I mean, you could just write out your code as if you already had the types specified and then fill in the boilerplate and fix errors afterwards. That's essentially what happens with dynamic typing anyway, so the only major difference is that your IDE/editor might notice.
Re:38% of bugs at Airbnb could have been prevented by using ... by victorNicollet on Monday February 11, 2019 @03:41PM (#19138095)
In a statically typed language, the code will not run until I have convinced the compiler that it should. If I wanted to explore the behaviour of `frobnicate` before committing to a design, I would still have to define all those satellite types that may well become unnecessary.
Re:38% of bugs at Airbnb could have been prevented by using ... by seanwilson on Monday February 11, 2019 @07:07PM (#19139789)
TypeScript lets you add the "any" type to say you don't care now. Solved?
Re:38% of bugs at Airbnb could have been prevented by using ... by victorNicollet on Tuesday February 12, 2019 @03:22AM (#19141927)
I mentioned Typescript as an example of language where I could do this, so... Yes?

Typescript is not a language I would say has a verbose type system.

Re:38% of bugs at Airbnb could have been prevented by using ... by Someone on Monday February 11, 2019 @12:20PM (#19136124)
I think the main reason some people say they prefer dynamically-typed languages is because of a feature that historically correlated quite well with it: they provide almost instant gratification.

There are two parts to that: no required boilerplate (“Hello, world!” shouldn’t require more than twice the number of characters, and requiring a manual compile-link step is a no-no) and low time to first output (who cares that each value carries a hundred or more bits of type info and takes an indirection to access, as long a as that “Hello, world” makes it to the screen in <100ms)

Historical counterexamples to the claim people prefer dynamic typing are the ROM-based Basics of the 8-bit computer era. Statically-typed, but popular, IMO because they ticked both boxes.

Re:38% of bugs at Airbnb could have been prevented by using ... by leshow on Monday February 11, 2019 @12:11PM (#19136021)
forget autocomplete, what about type inference? We've had that for decades yet new languages still come out without good support for it.
Re:38% of bugs at Airbnb could have been prevented by using ... by seanwilson on Monday February 11, 2019 @04:35AM (#19133134)
> Typing out code tends to be a minor part of writing software, so you don't gain much there. Furthermore, you don't want to mix types in the same variables either, because this comes at a cost of performance and complexity.

> So, what kind of flexibility do you get from dynamic typing?

I'm the same, I don't get it at all. If you're going to voluntarily opt-out of automatic safety checks you better have a mind blowing list of good reasons for it.

Re:38% of bugs at Airbnb could have been prevented by using ... by wutbrodo on Monday February 11, 2019 @07:49PM (#19140014)
Serendipitously, I actually had the occasion to do a code review of some Tensorflow code in C++ today and man was it narsty compared to what it would have been in Python. this is pretty much the kind of thinking of when I mentioned libraries being cleaner in ways where the trade-off is worth the loss of information.