Showing posts with label C. Show all posts
Showing posts with label C. Show all posts
Dennis Ritchie: This has always been a bit of a mystery to me to understand in any kind of detail. Obviously the use of C[1] was during early times (meaning the '70s and much of the '80s) considerably encouraged by its use as the lingua franca of Unix during the period that Unix was growing in the research and academic community, and then when Unix was taken up as the software basis for the workstation industry of the '80s. This in turn had to do in part with the non-political nature of C and Unix (not tied to a power in computer hardware until post-1984). There were also technical and semi-technical aspects: the language turned out to be well-placed both for describing things at a high enough level so that portability across hardware was feasible, but simple enough in its requirements to make it cheap to implement.
Bjarne Stroustrup: C and C++ became popular because they were flexible, cheap, and more efficient than alternatives. C owes much of its initial popularity to the popularity of Unix. C++ owes much of its initial popularity to its high degree of compatibility with C.
It was very important success of C and C++ that AT&T didn't try to monopolize these languages, but allowed its researchers to support the creation of alternative implementations. Also, AT&T fully supported ANSI and ISO standardization of C and C++ as soon as these efforts started. There was no systematic marketing of C or C++ before they became established languages and multiple vendors started competing. This non-commercial spread of C and C++ appealed strongly to many programmers.
Java is a very different design from the other two languages and appears to have a very different philosophy. It owes much of its initial popularity to the most intense marketing campaign ever mounted for a programming language. From its initial commercial debut onward, Java was marketed as radically different from, and better than, all other languages. Interestingly, Java was marketed to individuals at all organizational levels -- not just to programmers.
I suspect that the root of many of the differences between C/C++ and Java is that AT&T is primarily a user (a consumer) of computers, languages, and tools, whereas Sun is primarily a vendor of such things.
Just to remind people: Both C and C++ were invented in the Computer Science Research Center of Bell Labs in Murray Hill and found their initial serious use within Bell Labs and AT&T. Then, Bell labs was the R&D arm of AT&T. Now, part of Bell Labs is the R&D arm of Lucent and part stayed with AT&T under the name "AT&T Labs."
None of these languages was radically different or dramatically better than other contemporary languages. They were, however, good enough and the beneficiaries of luck and "social" factors such as Unix, low price, marketing (Java only), etc.
Among technical factors, C and C++ benefited from their closeness to machine and absence of artificial restrictions on what can be expressed. That allows low-level systems work to be done in these languages and for the full performance of a machine to be delivered to its users. Java benefited from running in its own virtual machine and from coming with a large set of libraries that decrease the time needed for a programmer to become productive. Unix gave a similar boost to C. In contrast, the C++ world suffers from fragmentation of its huge base of libraries, many of which are proprietary and supplied by competing vendors.
James Gosling: I think that the number one reason is that it's been generally a very pragmatic family of languages. By and large they weren't experiments in language design; they were put together as tools by people who wanted to do something else. C was very largely driven by the writing of the Unix operating system and all the utilities in it, and so a lot of the things that are in C are straight from what it takes to build an efficient operating system, and also what it takes to do that on a machine that only has 32K.
Forget C, use C++, and learn STL.
Note: I used STL and the C++ Standard Library interchangeably in this answer (though I probably shouldn't have). All the below structures and algorithms are in the C++ Standard Library, so it's what you need to learn.
All of the following are must-knows:
Data Structures
You should know how to use all these + all their related functions + the time complexity of all these functions + (probably) how these functions work
vectors(dynamic arrays) - know why push_back is amortized constant, not just that it is somapsandsets(red-black BSTs usually)unordered_mapsandunordered_sets(hash tables)stacks/queues/deques/listspriority_queues(though I'd argue in an interview you should just use amapsince it can do anything apriority_queuecan do and more)
You should also know what iterators are and how to use them with the above data structures and below algorithms, because you need to when using STL.
Graphs are also important to know how to implement. For interviews, I usually use a vector of vectors for an adjacency-list (or even adjacency-matrix) representation just because it's fast to implement and usually is sufficient enough for you to write your algorithm, but alternatives are also feasible and some people may prefer building it from scratch using classes/structs/pointers. In many cases you can just forgo building the graph completely during an interview and assume you have it given, and in some cases you shouldn't build the graph at all, but rather have your algorithm dynamically generate the needed parts as it executes.
Algorithms
Aside from all the related functions for the data structures above, the
algorithm library is extremely important, and you should probably know every function in it as well as how it's implemented and its time/space complexity (because all of these are fair game for interview questions and you might be asked to implement them from scratch, though probably without as much generalization as STL). Here are the most important ones, though, in my opinion:
sortstable_sortnth_elementlower_boundupper_boundmerge/inplace_mergenext_permutation/prev_permutationrotatereverse
Familiarizing yourself with the various math functions via the
cmath library is probably also a good idea, just in case you need them, though if you need a
tan function in an interview you can probably just tell your interviewer "I'm going to assume I have a function to calculate
tan(x)" and it'd be fine.
Pointers, Classes/Structs, and OOP Concepts
You should know these at least enough to make a linked list and trie (which are the most useful data structure that is not implemented in STL) in about 5-7 minutes, complete with an insert (or search) function (and yes you may be asked to do this in an interview). You should be very comfortable with them - I doubt pointers and classes will be explicitly asked about (you might be asked about OOP Concepts though), but you may very well have to use them.
Why You Should Know All This
Read this answer for the full version: Jimmy Saade's answer to How do I get a job at Facebook or Google in 6 months?
But basically, there are a lot of questions which rely on you knowing/having/being able to use these data structures/algorithms directly, without implementing them - especially
sort and
vectors,
maps, and
unordered_maps. Your solution to the asked question may require a hash table or heap to achieve a decent time complexity, or require that you sort the input - are you really going to implement these in the span of a 45 minute interview? No, and neither are you expected to. You're expected to make it easy on yourself and use STL, because the rest of the algorithm you're coding up is already going to be complex enough, plus you're never going to that in real life, and it shows you know not to re-make stuff that's already at your disposal.
The exception to this is if you're explicitly asked to implement something already in STL. For example, if you're asked to implement the
next_permutationfunction, you obviously shouldn't use the STL function, though you could (and probably should) note that there is such a function in STL. But basically the interviewer is looking for you to figure out the algorithm and code it yourself.
The theory version of this question is answered here: Jimmy Saade's answer to What should I know from CLRS 3rd edition book if my aim is to get into Google? and so they kind of go together in that what's listed in this answer is an implementation of the concepts listed in the other.
Damien Katz, Couchbase, believes that C is still a great language for back-end programming, while other developers argue that C has too many flaws, supporting C++ or Java, while others like neither.
Most things you use are built on a layer of C. Including your operating system (a C kernel, whether it's Windows, Unix, MacOS, iOS, Android or ChromeOS); the Java Virtual Machine (built in C); the browser / javascript virtual machine (built in C).Embedded systems often use C. C is a very powerful and efficient language, that can provide low level interaction with the hardware.
Why to choose C language
- Most languages are ultimately implemented in C (at the bottom-most layer). So to understand what your computer is really doing you need to know C.
- You don't have a choice if you're writing kernel code, or device drivers, or other low-level stuff - it has to be done in C (in most cases)
- In many of the high level languages (like Python, Perl, Ruby, Android's Java) when you need to optimize for performance, you rewrite the most critical parts in C.
- Your job in college isn't to learn "languages". It is to learn computer science, and programming. Data structures, algorithms, writing good code - structured and modular programming, good software engineering practices, converting a vaguely defined real-life problem into a program specification, breaking up a program specification into a program design, breaking up a problem into pieces that can be solved, debugging, knowing where to look for answers when you get stuck, knowing how to separate the useful information from the trash in google searches - these are all far more important than which language you learn.
- Your primary purpose is college is not to get a job - but to get an education. You want to learn how to be a good computer scientist and a good programmer. Do not make your job and current market conditions the basis of your decisions. What is "hot" in the current job market changes every 5 years.
The C programming language is a structure oriented programming language, developed at Bell Laboratories in 1972 by Dennis Ritchie. C programming language features were derived from an earlier language called “B” (Basic Combined Programming Language – BCPL).
C language was invented for implementing UNIX operating system. C belongs to the structured, procedural paradigms of languages. It is proven, flexible and powerful and may be used for a variety of different applications. Although high-level, C and assembly language share many of the same attributes. The C program is the human-readable form, while the executable that comes out of the compiler is the machine-readable and executable form. What this means is that to write and run a C program, you must have access to a C compiler. C is one of thousands of programming languages currently in use. C has been around for several decades and has won widespread acceptance because it gives programmers maximum control and efficiency. C is an easy language to learn. C belongs to the structured, procedural paradigms of languages. It is proven, flexible and powerful and may be used for a variety of different applications. Although high-level, C and assembly language share many of the same attributes.Features of C programming language Reliability Portability Flexibility Interactivity Modularity Efficiency and Effectiveness.
C language was invented for implementing UNIX operating system. C belongs to the structured, procedural paradigms of languages. It is proven, flexible and powerful and may be used for a variety of different applications. Although high-level, C and assembly language share many of the same attributes. The C program is the human-readable form, while the executable that comes out of the compiler is the machine-readable and executable form. What this means is that to write and run a C program, you must have access to a C compiler. C is one of thousands of programming languages currently in use. C has been around for several decades and has won widespread acceptance because it gives programmers maximum control and efficiency. C is an easy language to learn. C belongs to the structured, procedural paradigms of languages. It is proven, flexible and powerful and may be used for a variety of different applications. Although high-level, C and assembly language share many of the same attributes.Features of C programming language Reliability Portability Flexibility Interactivity Modularity Efficiency and Effectiveness.When Ritchie wrote C, he was not trying to create a language that was well-suited to creating programs that could use objects to describe real-world problem domains. He was trying to create a higher-level language than assembly which could still have very fine-grained control of the system's hardware.
Object-oriented languages are handy for creating applications that involve discrete entities which send messages to one another to get work done. C is good at efficient memory usage (if you know what you are doing) and direct communication with physical hardware, like disk drives and network ports.
You could just as easily ask, "Why wasn't the Ford Mustang a hovercraft?" When the Mustang was first produced, hovercraft technology had already been figured out. The Mustang could have been a hovercraft - but the hovercraft solved problems (travel over variable terrain & amphibious travel) that Ford wasn't trying to address.
Object-oriented languages are handy for creating applications that involve discrete entities which send messages to one another to get work done. C is good at efficient memory usage (if you know what you are doing) and direct communication with physical hardware, like disk drives and network ports.
You could just as easily ask, "Why wasn't the Ford Mustang a hovercraft?" When the Mustang was first produced, hovercraft technology had already been figured out. The Mustang could have been a hovercraft - but the hovercraft solved problems (travel over variable terrain & amphibious travel) that Ford wasn't trying to address.
