python

Displaying 1 - 5 of 5

Stack traces, backtraces, call stacks explained in JavaScript, Python, PHP

People are rarely happy to see a stack trace. A stack trace often appears when software encounters an exception, an unexpected error which can't be handled gracefully and therefore most stop execution of the program. What the stack trace shows is what was happening in the moments leading up to the bug. The stack is called a stack because each item (each function call) is stacked on top of the previous one in a special part of computer memory called the stack. Most computers and programming languages work with a stack. In programs written in programming languages without side effects, a...

Python-like List Comprehensions in JavaScript

Python has a neat syntactic feature where you can take a literal list constructor's bracket notation (e.g. [2, 4, 6, 8, 10]) but have code statements generate the list's contents. So instead of writing out the 5 even numbers in the example, one could write [(x+1)*2 for x in range(5)] which turns out to be more characters but you can imagine the savings if the series in the list was longer. Instead of range() we could have a literal list [0, 1, 2, 3, 4] or even a generator function, anything which is iterable.

How could we do this...

List Comprehensions in PHP (how to emulate Python)

Python has a sweet syntactic feature where you can take a literal list written out in bracket notation (e.g. [1, 3, 5, 7, 9]) but have inline expressions generate the list's contents. So instead of writing out the 5 consecutive odd numbers like above, in Python we can say [(x*2+1 for x in range(5)] which turns out to be more characters but you can imagine the savings if the series in the list was longer and not just odd. Instead of range() we could have a literal list [0, 1, 2, 3, 4] or even a generator function, anything which is...

Top 5 Programming Languages to Learn in 2016

It's a new year in a world that's moving faster than ever. This means it's important to keep up to date on technology, and young people who would have not been programmers before need to learn to code. There are various lists of programming languages by popularity of demand but they are too broad to read at face value. I've seen many people fail to learn a programming language when they had nothing to apply it to and were simply learning how a language works. It's a bit like learning a foreign language by reading a dictionary. The following list are my choices (not necessarily in order)...

Choosing Shell script vs Python vs Node.js vs PHP for Server-side Command Line Scripting

After decades of improvements in graphical user interfaces, the Unix command line interface still remains the most powerful way to get things done for a lot of workflows. This is due to many reasons: the difficulty of quickly and precisely moving the mouse cursor compared to the ability of touch typists to select exactly what they want (even when it's via hotkey combinations), but mainly (IMO) the expressive power of composing separate Unix commands into one pipe-separated command operating on standardized files (usually text).

It's also easy to write your own Unix commands which...