Free Programming Language Paradigms Cheat Sheet
Free Programming Language Paradigms Cheat Sheet
One of my favorite books on programming languages has been 7 Languages in 7 Weeks. You really get a sense of how diverse programming languages can be, and some feel powerful in completely different ways. When youre at an interview, youll often get asked to compare and contrast a programming language you use with another language. Often times, this will kick off a brief discussion of programming language paradigms. Here are some paradigms to become familiar with:
This is a cheat sheet from the Coding for Interviews Udemy course. For more, see https://www.udemy.com/programming-code-interview/?couponCode=CHEATSHEETERS
Prototype-based OO languages implement this by cloning instances. Notably, Javascript is prototype-based (as are other ECMAScript-based languages like AS3). Additionally, classes and class hierarchies can be implemented within a prototype-based framework.
prior to runtime, so you can often declare variables in these languages without specifying a type (a = 5 instead of int a = 5). Statically-typed languages are sometimes preferred because you can often catch type mismatch errors at compile-time. So if you call a function with a string instead of an integer, youll know much faster (maybe even within your IDE). In a dynamically typed language, often it will be difficult for any system to detect an error until that piece of code get hitlike when a user visits your website! For this reason, I am a big advocate of the importance of writing tests for dynamically-typed code. Static type-checking rules out a pretty common class of bugs during developmenttype mismatches. Polymorphism, in general, refers to the ability to provide the same interface for different underlying implementations. For allowing different behavior based on parameter types, this is sometimes called parametric polymorphism. Polymorphism referring to the object-interface separation is known as generic programming.
Concurrency
Concurrency is different from asynchronous callbacks. While Javascript uses callbacks all the time, they are implemented using an event loop. Concurrency, on the other hand, is implemented by using multiple threads.
This is a cheat sheet from the Coding for Interviews Udemy course. For more, see https://www.udemy.com/programming-code-interview/?couponCode=CHEATSHEETERS
C++: imperative, object-oriented (class), call-by-value/reference1 (kind of has generics2 , functional3) Java: imperative, object-oriented (class), has generics, reflective, call-by-value Javascript: imperative, object-oriented (prototype), call-by-value, functional C#: imperative, object-oriented (class), call-by-value/reference (kind of has functional4 ) C: imperative, call-by-value
Conclusion
We learned about: 1. Imperative vs. functional programming 2. Implementing object orientation using classes vs. prototypes 3. Passing arguments through to functions call-by-reference vs. call-by-value vs. call-by-object-reference-value 4. Concurrency vs. simply supporting callbacks Be sure to learn what paradigms your language of choice supports and any applicable caveats. Now when your interviewer asks you about your language, you can start an interesting conversation about how your language is different from all the others! If you get really into this stuff, theres a great course and book online where you learn to build your own programming language. The author created the Thin web server, and a student from this course ended up writing the popular Javascript language CoffeeScript!
call-by-reference using &. e.g., void call_by_reference(int &a_reference) via templates 3 C++ 11 adds some support for functional-style programming 4 only support for lambdas
1 2
This is a cheat sheet from the Coding for Interviews Udemy course. For more, see https://www.udemy.com/programming-code-interview/?couponCode=CHEATSHEETERS
Resources
1. 2. 3. 4. 5. Lecture on Programming Paradigms from the University of Birmingham List of multi-paradigm languages from Wikipedia More on Javascripts event loop Is python call-by-value or call-by-reference? Neither C++ values vs. reference
This is a cheat sheet from the Coding for Interviews Udemy course. For more, see https://www.udemy.com/programming-code-interview/?couponCode=CHEATSHEETERS