Readit News logoReadit News
pzh · 9 years ago
For me the biggest downside of dynamically typed lanaguages like Python and Javascript is that a small error in passing a function's parameters can propagate very far in a complex system. E.g. if you mistakenly interchange two consecutive function parameters, you could spend several hours debugging the effect several modules down. This is an error that a C++ compiler would catch right away.
makecheck · 9 years ago
C++ is not always able to detect common parameter errors, especially for things like implicit conversions of numbers. Arguably Python’s option of keyword arguments make certain classes of parameter errors go away, too.

Several years ago I remember someone who (perhaps unwisely) wrote a C++ function with many floating-point values as parameters and a single default "bool". At some point the function was extended to have another float. The compiler did not catch calling code that failed to add an extra float; it simply allowed the formerly-flag arguments to be assigned to the new float argument instead. In fact, implicit conversion of parameters is such a common C++ problem that I occasionally define wrapping types for the sole purpose of being parameter types: then the compiler has to trip over them when they are used incorrectly and callers have to do some kind of explicit action to indicate what their values really are.

mathw · 9 years ago
Those implicit conversion rules (largely inherited from C) are one of the bits of C++ that bit me the most when I was a primary C++ dev.
falcolas · 9 years ago
The cpp compiler would catch it only if the incorrect data was of a different type. Type specification and hinting only helps with the more egregious mistakes.
kevin_thibedeau · 9 years ago
Type hints can catch most of these mistakes.
humanfromearth · 9 years ago
There are solutions for this: flowtype for js or mypy for python (preferably with python3.5+).
inlineint · 9 years ago
The article doesn't mention type annotations described in PEP484 and added to CPython since Python 3.5.

It is possible to add annotations to your code like

    class Foo:
        x: int
        # ...
and then run type checks using `mypy`, so that for the annotated code probability of the "passes the checks => won't crash the runtime" case is much larger.

striking · 9 years ago
Sure, but most python code isn't annotated, right?

So this might be helpful for code you wrote, but not anywhere it interfaces with other peoples' code (which, in my opinion, is probably the most important place to check for type errors).

asddddd · 9 years ago
The older method is docstrings (reST and similar) like here: https://github.com/kennethreitz/requests/blob/master/request...

IDEs like PyCharm can use those and other methods to find most typing issues. In practice this is very effective for most "boring" Python code, but if you get really clever it falls over completely.

humanfromearth · 9 years ago
True, but very popular packages are usually battle tested and type errors are very rare in practice in those packages. Most bugs I've seen are not because of the lack of a static type system.
Rapzid · 9 years ago
Plus, many packages dynamically add members, stomp named parameters by wrapping stuff with kwargs, etc.
fernly · 9 years ago
Or specifically to his example,

    from typing import Dict
    Foo = Dict[int:str]
    def __init__(self, name:str, balance=0.0):
        """Construct a Klass."""
        self.myfoos = {} # type: Foo
I _think_ that's right... close anyway

tyingq · 9 years ago
Interesting, but it's mostly a few observations about interpreted vs compiled and static vs dynamic typing. And a bit about having a rich collection of 3rd party libraries.

The article wouldn't have been much different had it been C++ vs Ruby/Perl/etc.

JustSomeNobody · 9 years ago
What is a "C++ programmer?"

On any given day, I poop you not, I'm writing either c#, java, c++ or any number of scrpting languages (perl, bash, python, JavaScript).

Do people seriously only use a single language these days!?

coldtea · 9 years ago
>Do people seriously only use a single language these days!?

Yes. In what bizarro world would one assume it's not so? By thinking that all development in the world resembles the company/work they do?

Tons of programmers only write C# or Java on Windows, and don't touch any shell scripting at all.

Tons of front-end developers only write Javascript.

Tons of statistics people only use R or 1-2 other statistics packages.

Tons of systems, drivers, embedded and OS people only C or C++.

Tons of game devs only write C++.

Tons of native mobile devs only write Swift, Objective-C or Java.

Some of them do occasional need to write some script to get something done, but it's hardly like the juggle between multiple languages.

And of course larger companies have specialized programmers for different domains, not some guy doing C++ AND admin stuff in shell AND some front-end JS etc.

ironman1478 · 9 years ago
The main product I work on is written in C++, so I spend most of my day looking at\writing C++ and also learning as much C++ as I can. I do use other languages for some minor tasks (python and c# for some automated test stuff and devopsish kind of work), but i dont use those languages as much as C++ nor do I invest as much effort into learning the ins and outs of those languages. So I consider myself a C++ programmer because its what I put effort into
programbreeding · 9 years ago
Some people are far more specialized in what they work on.

- Apple's Swift codebase is 54.8% c++ [0]

- Microsoft's CNTK codebase is 57.6% c++ [1]

- Bitcoin's codebase is 68.6% c++[2]

- XBMC's codebase is 84.7% c++[3]

If you work on certain or specific types of projects, like ones making the tools that others use do their projects, then you are typically working more in only 1-2 languages at a time.

[0] https://github.com/apple/swift

[1] https://github.com/Microsoft/CNTK

[2] https://github.com/bitcoin/bitcoin

[3] https://github.com/xbmc/xbmc

Deleted Comment

Twirrim · 9 years ago
Why do you jump between multiple languages all the time?
v1n337 · 9 years ago
Not, OP, but I've worked for an ad-agency in a software-dev role.

Their primary code base is written in Java, monitoring scripts in Python/Ruby, and tracking pixel code in JavaScript, so I would have days in which I coded in all 3, albeit for separate use-cases.

grigjd3 · 9 years ago
Different tools for different tasks. Not gonna use C to analyze some text files...
JustSomeNobody · 9 years ago
Best tool for the job.
Twirrim · 9 years ago
For what it's worth, python has been making inroads in the HPC world as well. In that context it seems like python is being used as the glue to tie highly optimized, custom written, C/C++ libraries together. http://lorenabarba.com/publications/http://dl.acm.org/citation.cfm?id=3019084&CFID=927535872&CFT...http://dl.acm.org/citation.cfm?id=2830170&CFID=927535872&CFT...

It's happening enough that there has been a series of popular conferences for it, PyHPC http://www.dlr.de/sc/desktopdefault.aspx/tabid-11992/21071_r...

Animats · 9 years ago
This reads like it was written 10-15 years ago. But apparently it's new.
pastaguy1 · 9 years ago
That's the same feeling I had when I was writing the article!
bbody · 9 years ago
Looks like the website's bandwidth limit hit its limit. Google Cache link for those who still want to read it http://webcache.googleusercontent.com/search?q=cache:Z6cJ7kw...
partycoder · 9 years ago
There are package managers for C++, such as Conan. Some IDEs like CLion have certain degree of integration with it.

https://www.conan.io

Then, some systems cannot afford to have garbage collection, because it usually runs in an unpredictable amount of time. Such systems are for example real-time systems. In those cases a language like C++ is a good fit.