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

前端 未结 20 1125
独厮守ぢ
独厮守ぢ 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:09

    The classic example that Joel Spolsky uses is on misuse of strcat and strlen, and spotting "Shlemiel the painter" algorithms in general.

    It's not that you need C to solve problems that higher-level languages can't solve, it's that knowing C well gives you a perspective on what's going on underneath all those levels of languages that allows you to write better software. Because just such a perspective helps you avoid writing code which is, unknown to you, actually O(n^2), for example.

    Edit: Some clarification based on comments.

    Knowing C is not a prerequisite for such knowledge, there are many ways to acquire the same knowledge.

    Knowing C is also not a guarantee of these skills. You may be proficient in C and yet still write horrible, grotty, kludgy code in every other language you touch.

    C is a low-level language, yet it still has modern control structures and functions so you aren't always getting caught up in the fiddly details. It's very difficult to become proficient at C without gaining a mastery of certain fundamentals (such as the details of memory management and pointers), mastery of which often pays rich dividends when working in any language.

    It's always about the fundamentals.

    This is true in many pursuits as well as software engineering. It is not secret incantations that make the best programmers the best, rather it is a greater mastery of the fundamentals. Experience has shown that knowledge of C tends to have a higher correlation to mastery of certain of those fundamentals, and that learning C tends to be one of the easier and more common routes to acquiring such knowledge.

    0 讨论(0)
  • 2021-02-05 13:09

    Not knowing Perl well, I am wondering if it is now possible to distribute processor load to more than one physical core with several threads created in a single program in Perl, without spawning additional processes

    0 讨论(0)
  • 2021-02-05 13:10

    To give you a specific reason: having to write my own Garbage Collection routines has helped my write better code.

    I don't think I have ever found a problem that I haven't been able to solve with a higher-level language; but started by learning C, it has instilled in me quite a number of excellent development practices. Knowing how the rudimentary parts of the flow of an application work will enable to you be able to look at your own code and get a good visual of how the data flows, and where it is stored. This then leads to a better understand of how to track down leaking memory, slow disk reads, poorly constructed caches, etc.

    Keeping track of Pointers... that's another one that comes to mind.

    0 讨论(0)
  • 2021-02-05 13:10

    You cannot write an OS kernel in Perl; C would be a much better choice for that, because it is low-level enough to express everything the kernel should do, and portable enough to let you port your kernel to different architectures

    0 讨论(0)
  • 2021-02-05 13:11

    Knowing C is great because it does nothing behind your back (GC, bounds checking, etc.). It only does exactly what you tell it too. Nothing is implied. Even C++ does things you don't tell it too with RAII (of course, it is implied that the object is destructed when it goes out of scope, but you don't actually write that). C is a great way to learn what goes on 'under the hood' of the computer, without having to write assembly.

    0 讨论(0)
  • 2021-02-05 13:13

    Knowing C is really not worth much. Many of us who know C deeply like to think that all that deep insight is valuable and important.

    Some of us who know C can't think of a single specific feature of C that's helpful to know about.

    Knowing how pointers work in C (especially with C's syntax) isn't all that helpful. In a high-level language your statements create objects and manage their interaction. Pointers and references are -- perhaps -- interesting from a hypothetical point of view. But the knowledge has no practical impact on how you use Java or Python.

    The higher-level languages are the way they are. Knowing how doesn't change those languages; it doesn't change how you use them, debug or test them.

    Knowing how to create or manipulate a linked list has no earthly impact on Python list class definition. None.

    Knowing the difference between Linked List and Array List might help you write a Java program. But the C implementation doesn't help you choose between Linked List and Array List. The decision is independent of knowing C.

    A bad algorithm is bad in every language. Knowing inner mysteries of C doesn't make a bad algorithm any less bad. Knowing C doesn't help you know the Java collections or the Python built-in types.

    I can't see any value in learning C. Learning Fortran is just as valuable.

    0 讨论(0)
提交回复
热议问题