grep for naming conventions

I’ve used grep for years, now, though in the past few days I found a nice combination of it and some other command line utilities to do a bit of an audit as to how I’m naming methods and variables in the code I’m writing.

-oh # that’s how it works

a shortcut for --only-matching, this option won’t show the whole line, just the part that matches your search criteria
a shortcut for --no-filename, this will hide the first part of the normal output, so you can look for trends across files more easily

Put these two together, and you can then pipe the output over many files into sort and uniq -c to get an alphabetized, counted list of every instance of the pattern you want to find. You can also then pipe that all into a final sort -n which will sort by the count, such that the biggest fish fall to the bottom.

Use case: camelCase vs. underscores

Putting this all together, you can get a general command something like this:

grep -oh $PATTERN $(find . -name \*${EXT}) \
	| sort | uniq -c | less

To find underscore_separated_words, use PATTERN='\w\+_\w\+'; for camelCase, let PATTERN='[[:lower:]]\+[[:upper:]]\w\+'.

Finally, set EXT='.php' to look over just your PHP files, or change it to any extension of the types of files you want to inspect. You can also use grep’s -r flag with a target directory if you want to recurse through all files, rather than limiting yourself to files with a particular extension.

FC: One Word Stress Relief

How 60 Seconds And One Word A Day Can Reduce Your Stress. Thanks to Sarah for the link. Below is half summary, but more in the way I’ve been seeing things lately.

Stop Hitting Yourself

The first part of the article seems more useful than the second, though both are on the same thread: basically, the point is to stop hitting yourself, with words. Saying negative shit is actually bad for you, and having a negative internal dialogue is even worse.

I’ve been guilty of this long enough myself to know that even making subtle, nicer changes in the words with which you describe yourself can make a big impact. You don’t have to be a double rainbow unicorn, but cutting the shit and doom and gloom is a good first start.

Stand Up

More and more at work, I’ve been conscious of trying to get up out of my chair, especially when there’s a difficult problem to solve. Brood mind can start to carry weight, so dust those shoulders off and shake it off before it takes over in other physical means.

Western Om

Last part is basically about holding one positive thought or idea consciously for 10+ second stretches. Sounds an awful lot like an Om. For me, a sound of silence seems to work better than a word, but if the western PEACE or PLUR or whatever gets you going, why not go for it.

Fist Bumps > Hand Shakes

from the AP, via Yahoo!. Makes sense. I’ve preferred this for a while now, though perhaps now it can gain a bit of traction.

STTaaS: Stern Talking-To as a Service

NYT: Love People, Not Pleasure

from the SundayReview. Great piece. I found it from a re-tweet, which highlighted this quote: “What do you post on Facebook? You build a fake life — an incomplete one.”

Mostly, though, I like this one: switch “Love things, use people” into “Love people, use things.”

Nothing earth shattering here, but definitely a good read, with some key reminders re: life.

Daring Fireball: Only Apple

Great article. There’s a lot of words, but it’s very well written and moves along at a good clip.

The article contrasts of the Apple today vs. where it was years ago, largely with the help of Tim Cook’s strengths as CEO.

Ars: Tracking goes offline

Why online tracking is getting creepier. Great, short article about an important topic.

“Email?” “No, thanks”

The long and the short from this article is that you should not give retailers or most any company your email address, if you can help it.

It used to be common practice to ask if you wanted to share your email address. The new pattern is to just ask for your address outright, as if it’s required.

In most any case you can just say “no, thank you,” and be on your way. You get all the perks, perhaps tinged with a slight moment of social awkwardness as you deviate from the standard script.

Global Opt-out

There are a number of good links, though these two are likely worth visiting ASAP: DMA Choice and LiveRamp Opt-Out. You can have these companies that gather addresses take you off their list, if only for a few years at a time.