Unstated coding style

Posted Dec. 21, 2011 at 6:03 p.m.

Programming style is definitely a project-to-project, author-to-author thing. Rarely do two projects share the exact same style unless the original authors are the same; even then, having consistency within a single project is sometimes a mythical goal that never quite gets achieved unless the maintainers keep a watchful eye on all incoming code.

Some projects try hard to document some sort of standard. For a few examples, we have the GNU Coding Standards, the Linux kernel coding style document, and the project I work most on, pacman, has a HACKING file documenting a few style guidelines.

However, this blog post isn't going to cover much of the typical programming style bullet points:

  • Indentation- width and tabs vs. spaces
  • Line length and wrapping
  • Vertical alignment- variable declarations, function prototypes
  • Whitespace within a line- after keywords, around arithmetic operators, comparison operators, assignment operators, commas, etc.
  • Brace placement in languages that need them
  • Naming conventions
  • Comment style, verbosity, and contents

Instead, let's focus on a convention that is rarely stated in a coding style manifesto: arithmetic ordering.

array[foo * 2 + 1] = 6;
value = (value << 3) * 5 + 18;

or

array[2 * foo + 1] = 6;
value = 18 + 5 * (value << 3);

My gut and eyes tell me that most people use the former forms in coding rather than the latter. An argument for the second form comes with this math expression: 2x + 1 as opposed to x2 + 1, which no one would ever use. However, this isn't the preferred form. This is rather interesting, and my guesses are the following:

  • Most programmers tend to put the variable on the left-hand side of comparisons: a < 2 rather than 2 > a, for example. The same logic holds here.
  • It reads better left-to-right. "take foo, double it, add one" rather than "take two, multiply by foo, add one".
  • In typed languages, having the variable rather than the constant first allows you to more quickly deduce the resulting type.

Are there other implicit conventions you have come across in code? I'd love to hear them.

Nginx memory usage with SSL

Posted Nov. 16, 2011 at 2:10 p.m.

The Nginx changelog for the 1.0.9 release (on November 1, 2011) had a single line note tucked away inside:

*) Feature: decrease of memory consumption if SSL is used.

It turns out two small tweaks made this possible: disabling SSL compression and releasing unneeded SSL buffers.

So why am I even blogging about this? This site surely isn't big enough to have this really make a difference, but the before and after on the graph of Nginx memory usage on the Arch Linux forums and wiki server is rather astounding, a site that does only HTTPS. If you use Nginx + SSL, I'd highly recommend upgrading.

Nginx memory usage

Disabling Firefox 7 trimmed URLs

Posted Sept. 28, 2011 at 3:44 p.m.

  1. Goto "about:config" in your address bar.
  2. Preference Name: browser.urlbar.trimURLs
  3. Double-click to set to false.

I've never liked this behavior in Chrome, but at least Firefox makes it super-easy to disable.

The MySQL Syntax Dartboard

Posted Aug. 22, 2011 at 10:57 p.m.

It is angry blog post night, but writing about them is a great way to stop thinking about problems. Time to play MySQL darts:

SHOW GRANTS ...;
SHOW INDEXES ...;
SHOW CREATE TABLE ...;

SHOW and DESCRIBE tend to be the goto commands in MySQL for doing basic database diving in the command line shell.

Three points to you if you can complete all three statements without looking them up in the documentation or via Google, or making any syntax errors. Answers are a few paragraphs down so you can't see them yet.

I'm going to ramble on here so the answers are hopefully more than a screen down.

Did you get it? Are you sure? Wouldn't want you to experience something like

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near ''archweb'@'localhost'' at line 1

Don't cheat!

Here are your answers.

SHOW GRANTS FOR 'archweb'@'localhost';
SHOW INDEXES FROM package_files;
SHOW CREATE TABLE package_files;

WTF, MySQL? Do you really find the need to use FOR, FROM, and the complete absence of a preposition in varying degrees across the multiple SHOW commands?

The full insanity is documented, and at least they had the state of mind to put a single table of all SHOW statements on the same page so you can see how horribly thought out their syntax planning was.

No Thanks, PayPal

Posted Aug. 22, 2011 at 10:21 p.m.

Got this lovely email from them yesterday:

Hello Daniel McGee,

We're writing to let you know about a change to your PayPal account.

Starting 8/21/2011, money from payments you receive will be placed in a pending balance for up to 21 days. By doing this, we're making sure that there's enough money in your account to cover potential refunds or claims.

Even though you can't access the money right away, please ship orders quickly and communicate with your customers. After 21 days, you can withdraw money from each payment as long as the customer hasn't filed a dispute, chargeback, claim, return, or reversal. The money may be available sooner if:

  1. We can confirm that the item was delivered.
  2. Your buyer leaves positive feedback. (Applies only to eBay items)

This change isn't necessarily permanent. We'll review your account every 35 days and re-evaluate if we should continue to hold your payments. If we decide to stop holding payments, we'll email you to let you know.

Why are my payments being held?
We reviewed your account and determined that there's a relatively higher than average risk of future transaction issues (such as claims, or chargebacks, or payment reversals). We understand that it may be inconvenient to have your payments temporarily held but please know that we didn't make this decision lightly.

Before deciding to hold payments, we consider many factors. These factors include account and transaction activity, the rate of customer disputes, the type of business a seller runs, average delivery timeframes, customer satisfaction, performance and history.

Questions? Let us know
We understand you’d like to have immediate access to the money you receive and we’re here to answer your questions about this change to your account.

For more information and tips on what you can do to avoid having your future payments held, please see our Frequently Asked Questions. To speak to a Customer Service representative, log in to your PayPal account and click “Contact Us” at the bottom of any page.

Thanks,
PayPal

Fuck you guys too. I do maybe one to two transactions a month with them, and this is totally out of the blue. I'm glad this isn't my primary incoming route of my freelance income. Hope this gives everyone second thoughts about doing anything with incoming payments and PayPal. Perhaps you can see why we were uneasy as developers over at Arch Linux using them as a donation bank.

Want to see more posts? Take a look at the archives or take a look at the tag list.