What’s wrong with this code? A bit of background for this example; `driver` is a Selenium::WebDriver object, the Selenium server is remote. Also, this technique is applicable to all expensive code that does the same thing over and over.
(driver.find_elements :id, "name")
Apart from being terribly contrived, this code is bad because every single interaction with
first_name_field causes a call to
find_elements, which in turn reaches out to the Selenium server. You’re adding a network round trip every single time, and for no reason. Instead of asking the browser to do this:
You’re asking it to do this:
This doesn’t just occur through Selenium commands (although Page Object Model code and libraries are often prone working this way). Loading configurations, accessing web services, validating data. There’s many places where you’ll burn up cycles (and correspondingly incinerate coal and warm the planet dooming us all just a liiiiitle sooner. Yeah, I actually do think wasted compute matters.) and, maybe more sellable to your Product Owner (who clearly doesn’t care about the environment), this will make your code faster.
Are you writing this down, and taking a memo?
No, like, literally. Take a memo. This kind of memo. Memoization is where you save the result of an expensive operation and return the saved result every time the operation is requested. Like responding to everything your Mum says on the phone with “Uhuh”, Memoization swaps one resource (computing time or brain-cells) for another (memory or engagement). Memory is cheap. You can probably throw more into your server if you need it. (But you don’t need it. Just… You don’t, trust me.)
If you use Ruby, you’re probably already taking advantage of Memoization:
@proscuitto_pizza ||= Pizza.new(:delicious)
That’s right, the
||= operator in Ruby effectively does Memoization; If the variable exists, it does nothing, else it sets it to the code on on the right of the operator. Wrap the whole lot up in a method name and you’ve got a memoized value.
For example, we could re-write the code above as so:
@first_name_field ||= (driver.find_elements :id, "name")
That single line change means that Ruby will remember the field in question and we won’t need to ask the Selenium server for it again, saving us a heap of time.
(Selenium Sidenote – Unless the page changes of course. How do you know if the page changes? Well, every navigation will do it (including those involving submitting forms) and some AJAX requests do it. You need to understand how your site is implemented… But then, you should anyway so you know what you’re actually testing).
(Some more reading on the ||= operator)
I don’t think humans should do boring or repetitive things. Humans are better at creating and learning then doing the things that machines can do faster and more accurately. This is a strong enough belief that I’ve put it in my resume.
My excellent friend Curtis Lassam seems to be of the same opinion, as his fun little romp, Automation For The People, demonstrates. You should go check it out (and mad props, Curtis, for using Github as a blogging platform). It’s funny, tells a great story, and you might learn something.
Entirely beside the point of whether you consider Lattes to have value, I assume you consider your career does? Maybe you’re working up to a glorious technocratic empire, constant spreads in Inc., Johnny Ive begging you to please, please come back to Apple. Perhaps you’d just like to not go bankrupt.
Avdi Grimm, Generally Awesome Person and Excellent Ruby Developer, would also like this. He posted this article explaining that, while he’s not in imminent danger of dying in debtors prison, he’s not liking his income trend.
This was probably a rough thing to admit because talking about money makes people weird and evidence of failure is often taken as evidence of deserved failure. To me it was rough to read because Avdi is an excellent developer who makes fantastic resources. I’ve loved reading Confident Ruby. I’ve been a subscriber to Ruby Tapas (his short-form screencast series) for over two years. If you’re wanting to invest some cash in your career, and have that go directly to a literal Ruby Hero, go read the blog post and then buy a book or subscribe to Ruby Tapas. You’ll get value out of them. And yes, I think they’re good for a developer’s work as at least two cups of coffee.
(I’m not being paid for this post; I don’t think I’ve ever met Avdi, I just think he’s made some nifty stuff and this was a good chance to turn you all onto it.)
A library to return the name and branding colour of a bank by the first few digits of a card number. It will also help you generate CSS files to use.
Changing the colours on a billing page to match the user’s banking colours, making you look impressively switched on (and maybe a little creepy).
There are only entries for users which have contributed them, so some banks will be unmatched (unless you contribute!).
Users may think you’re stealing their credit card information, despite the fact that they’re literally about to give it too them.
npm install banks-db
Ensure my bank is present? Like So.
Get the docs and source? Right Here.
Git (and its ilk) are tools for working collaboratively (especially with hosted services). Your commit messages are your best weapon for communicating context, and every collaborator, including Future You, depends on context to be productive. It’s not opinion, it’s Science!
See, human memory is so bad it can be erased by passing through a doorway. We can defeat doorway-induced time wasting (not to mention the change of screaming “what the hell is this?!” at code someone, maybe Past You, wrote) with great commit messages.
(Image courtesy of XKCD because Randall is a champ.)
A great commit message:
All this info, the context of the change, makes problem solving (read: coding) more efficient. Good context helps any collaborator; there’s evidence that context-based approaches to problem solving are more effective.
I just got upgraded to the Business lounge at Sydney Domestic. I think it’s because it’s 8pm and the other lounge is closing.
Immaterial differences: table service, slightly more expensive furniture, less people.
Material differences: stabilised atmosphere Wine By The Glass machine. Oh my yes.
Travel is *awesome*.
I generally don’t make New Years Resolutions. The entire process is so arbitrary and self-loathing, it plays into the whole annus horibilis bollucks. If you’re going to improve your life, just do so; Don’t wait for some arbitrary point to go this is the year I will be self fulfilled, all my dreams will approach realization, I will open my code chakras and purge my stale git stashes and finally learn how the hell to use Vim. If you’re constantly trying to learn new things you’re going to be better off then it you wait to be pushed by the last two digits of the date++.
At least pick more then one point in the year to fix ALL The Things. One thing a month. You’ll get continuous benefits for your life and won’t be exhausted from trying to change everything all at once. You don’t want to go through all the stress of making a change, just to suffer from a fit of Extinction Bursts all at once. Failing at multiple goals at once can lead to feeling like a children’s toy that’s been run over, by a leaking sewerage truck, in the rain: Useless, disgusting and prone to making gross squelching sounds.
However. It’s excellent blog credit to give a list of your New Years resolutions; Gotta get those views, that’s how you get that Internet Monies from the Internet People (Or so I hear). So instead of giving my resolutions, I’m going to make some suggestions that everyone else could adopt. Please feel free to give me all the credit for these, despite the willpower being expended by you and you alone. There’s going to be twelve in total, one for each month. Here are the first three, and I’ll publish the rest every quarter, just to kill off the temptation to start them all at once.
Learning a new technology has an obvious benefit: It makes you more employable. Personally I think this is the least beneficial aspect. Learning a new tech, especially one that is wildly different from what you do day-to-day, makes you better at your current job.
It’s been solid advice for a while, that learning a different programming paradigm makes your code better in all languages. I don’t actually buy this. “writes Java in Ruby” is the same as “acts Functionally in JS“; they’re both paradigm contamination. I think that practise makes you better, but that’s a very different thing.
No, the reason that I think learning a tech makes you better at your job is it lets you talk to other developers in their language, shows you the strengths of technologies that might make your own specialty more useful, and allows you to better boot-strap individual projects. A shinier prototype is more likely to be turned into a Real Project.
I personally really like Code School for learning new tech. I gave up on books because it’s difficult to know what’s worth reading and what isn’t, until you’ve enough experience to evaluate the content and, well… that experience is what you’re reading to build. I like Code School because it treats the viewer like an adult (unlike at least one competitor) and because it builds in logical, sensible ways. I’m not getting paid for this recommendation (although if Code School wants… call me!), I just like the product.
Capitalism is pretty gross. It’s also widely entrenched in society and unlikely to be replaced by anything better before the AI post-scarcity uprising, and I hear that project didn’t meet its KickStarter goal. Money is here to stay, and Money roughly correlates with ability. Not ability to accomplish tasks; ability to get others to help (or at least get out of the way).
Spare funds give you the ability to quit and find a better job. Spare funds allow you to buy tools for your hobby and improve your mental health. Spare funds let you travel. Spare funds let you start a side project, that gets profitable, that makes you more spare funds. It’s kind of crap that having money makes it easier to make money. It makes life less stressful. It literally makes you less sad and maybe happier up to a point (The literature is mixed. This is a nice summary. TL;DR Money gives you options. Wow, what a familiar argument…).
This is not financial advice. I do not know what your goals are… But maybe you’re lucky enough that with focus and willpower, you can put yourself in a place with more ability to achieve them. Maybe start with an Emergency Fund?
This one is pretty easy: Get more involved in a tech community. The cold hard reason is that it’ll serve as good networking. Screw that. Tech is (or should be) fun. Tech people are some of my favourite kinds of people. There are meetups for languages and tools and industries all over the world. Go to a conference (like RubyConf.au!) and deliberately talk to people you don’t know. Head to your local meetup. Join and post to some Open Source Mailing lists.
If you’re already involved, step it up. Pitch talks to conferences and meetups. Organize an event. Go to a longer event or workshop (Rails Camps are amazing). Mentoring is a huge benefit to our industry, so find a junior dev and offer. Help less-connected people get integrated by going with them to events and introducing them to others.
Especially try to find unique and interesting voices and share them with others. We can be faddy, prone to hero worship and appealing to authority. Mix it up! Share things you don’t often here, from people who aren’t often heard. Everyone gets better that way.
I really really can’t stand New Years Resolutions, which is why this post is deliberately delayed. All of these are suggestions of things that I’d like to accomplish myself, and may be helpful in your life. They’re not aimed at anyone in particular, nor do I warrant their practicality or easy. Any feedback, leave a comment below!
Something that will, sadly, not be a secret to many of you: Some people are awful.
Even if you think it’s acceptable to be a rude arrogant jerk to people in private, (and would you want, as queer person, to work with someone you know donates heavily to prevent marriage equality, even ‘in private’?) it’s very hard to argue that it’s OK in professional life. Open Source is no longer just a fun hobby; it’s a professional reality that you will use and (hopefully) contribute to Open Source. Unfortunately there are people in many many projects, often in significant roles, that will say things that are cruel, hurtful, that erase and trivialise people’s identities and personal triumphs and disadvantages. They’re being bullies ‘at work’. That’s super NOT OK.
One of the best ways to make communities professional and welcoming to beginners, as well as enhancing diversity, is to adopt and enforce a Code of Conduct. Ashe Dryden answers all of the questions you might have about why and how far better then I could, but I want to re-enforce five things:
And number five:
begin objection.text = "but you're discriminating against my right to discriminate!" rescue RediculousCircularObjectionException => e objection.deny objection.objector.judge :pretty_harshly objection.objector.rebutt "Really? Really. You think that's a coherent argument?" end
You know who’s not awful? Coraline Ada Ehmke. She’s actually really great. She’s proposed a Code of Conduct for Ruby Core (and wrote the original Contributor Covenant) and you can find that proposal here. All y’all with Core Ruby accounts should go support it.
What do we have to lose? Awful people, that’s what. HUZZAH!
|English Afrikaans العربية Беларуская български català česky Cymraeg dansk Deutsch ελληνική español eesti فارسی suomi français Gaeilge galego||עברית हिन्दी hrvatski magyar bahasa Indonesia íslenska italiano 日本語 한국어 lietuvių latviešu македонски bahasa Melayu Malti Nederlands norsk polski português||română русский slovenčina slovenščina shqipe српски svenska Kiswahili ภาษาไทย Filipino Türkçe українська tiếng Việt ייִדיש 中文 (简体) 中文 (繁體) powered by|