In my last post, I complained about my initial experience with Stack Overflow. I decided to give myself 30 days with the service, to see whether or not I warmed up to it. Now that those 30 days are over, I will be posting several of my thoughts and observations. This first post won’t be about the site itself; instead, it will cover some of the things I learned during my 30 days. A second upcoming post will cover some problems I think exist with the Stack Overflow model, and my final post will provide a few suggestions for how I think things can be improved.
Let me first say that I learned a lot simply by browsing the site. Reading existing questions and their answers was fascinating, at least for the programming topics I care about. Some of what I learned came through mistakes I made attempting to answer open questions. Other bits of information just came through searching the web for the solution to someone’s problem (something that a lot of people at Stack Overflow are apparently too lazy to do). Without further ado, here’s a list of stuff I learned, in no particular order (each item lists the corresponding language):
- C (with GNU Extension), PHP (5.3+)
- The true clause in a ternary compare operation can be omitted. In this case, the first operand (the test) will be returned if true. This is a bizarre shortcut, and one I would never personally use. Here’s a PHP example (note that there’s no space between the question mark and the colon; in C, a space is necessary):
$a = $b ?: $c; // No true clause (too lazy to type it, I guess) $a = $b ? $b : $c; // The above is equivalent to this
- Regular Expressions (Perl, PHP, possibly others)
$in a regular expression doesn’t literally match the absolute end of the string; it can also match a new-line character that is the last character in the string. Pattern modifiers are usually available to modify this behavior. This fact was a surprise to me; I’ve had it wrong all these years!
- I found a terrific article that details the differences between
- Firefox Extensions (XUL, JS)
- You can use the addTab method in the global browser object to inject POST data to a newly opened tab.
- The way I learned to open files for output in Perl (over a decade ago) is now not advised. It’s going to take a lot of effort on my part to change to the new style; old habits, and all that.
# Old way of doing it (how I learned) open OUT, "> myfile.txt" or die "Failed to open: $!"; # The newer, recommended way (as of Perl 5.6) open my $out, '>', "myfile.txt" or die "Failed to open: $!";