Oh Dear is the all-in-one monitoring tool for your entire website. We monitor uptime, SSL certificates, broken links, scheduled tasks and more. You'll get a notifications for us when something's wrong. All that paired with a developer friendly API and kick-ass documentation. O, and you'll also be able to create a public status page under a minute. Start monitoring using our free trial now.

When are single-character variable names acceptable?

Link –

Generally I don't like to abbreviate variable names. This answer on Quora lists a few situations where an abbreviation is probably ok.

There is a simple (but unsatisfying) answer to all questions of this form: they are acceptable when they would make the code clearer.

This can happen in a few ways. The most common, as you noted, is convention: i, j, k for loop variables, x and y for coordinates, e for exceptions, f and g for functions and so on.

Another is structure. Often, the broad structure of an expression is more important than its contents. Using shorter variable names makes it easier to read at a glance. I think this is often more important than being easy to read in detail!

If a variable has a very small scope—say one or two lines at most—and it's easy to see where it comes from, having a long name is just noise.

https://www.quora.com/When-are-single-character-variable-names-acceptable/answer/Tikhon-Jelvis

Stay up to date with all things Laravel, PHP, and JavaScript.

You can follow me on these platforms:

On all these platforms, regularly share programming tips, and what I myself have learned in ongoing projects.

Every month I send out a newsletter containing lots of interesting stuff for the modern PHP developer.

Expect quick tips & tricks, interesting tutorials, opinions and packages. Because I work with Laravel every day there is an emphasis on that framework.

Rest assured that I will only use your email address to send you the newsletter and will not use it for any other purposes.

Comments

What are your thoughts on "When are single-character variable names acceptable?"?

Comments powered by Laravel Comments
Want to join the conversation? Log in or create an account to post a comment.