What is an example in which knowing C will make me write better code in any other language?

前端 未结 20 1163
独厮守ぢ
独厮守ぢ 2021-02-05 12:40

In the Stack Overflow podcasts, Joel Spolsky constantly harps on Jeff Atwood about Jeff not knowing how to write code in C. His statement is that \"knowing C helps you write bet

20条回答
  •  暖寄归人
    2021-02-05 13:21

    In Python, say you have a function

    def foo(l=[])
      l.append("bar")
      return l;
    

    On some version of Python, available about a year ago, running foo() for times, you'd get a really interesting result (i.e. ["bar","bar","bar","bar]).

    It seems that someone implemented the default parameters as a static variable (and without resetting it), so unexpected results happen.

    Perhaps my example was contrived - a friend of mine who actually likes Python found this peculiar bug, but the fact of the matter is all of these languages are implemented in C or C++. Not knowing and not understanding concepts that are fundamental to the base language means that you won't have an in-depth understanding of languages that are built on top of that.

    I find all the "why bother with C/C++/ASM question silly". If you're inclined enough to learn a language, that means that you're curious enough to get into it the first place. Why stop at just before C?

提交回复
热议问题