<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tom Butterwith</title>
    <description>The latest articles on DEV Community by Tom Butterwith (@tbutterwith).</description>
    <link>https://dev.to/tbutterwith</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F5111%2F040d979d-1399-4f88-bebe-f29248fa8daf.jpg</url>
      <title>DEV Community: Tom Butterwith</title>
      <link>https://dev.to/tbutterwith</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tbutterwith"/>
    <language>en</language>
    <item>
      <title>Becoming a Highly Effective Software Developer</title>
      <dc:creator>Tom Butterwith</dc:creator>
      <pubDate>Mon, 30 Sep 2024 13:40:11 +0000</pubDate>
      <link>https://dev.to/tbutterwith/becoming-a-highly-effective-software-developer-4eem</link>
      <guid>https://dev.to/tbutterwith/becoming-a-highly-effective-software-developer-4eem</guid>
      <description>&lt;p&gt;Senior engineers often ask me, 'What do I need to do to get promoted?’ While technical skills are crucial, the most effective engineers possess qualities that go beyond writing code. Here are a few traits that I feel highly effective engineers embody: finishing over starting, fostering growth in others, and mastering communication.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Focus on Finishing Over Starting
&lt;/h2&gt;

&lt;p&gt;Effective engineers understand that completing work is more valuable than starting work. This principle manifests in several ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Supporting Others' Initiatives&lt;/strong&gt;: Instead of always pushing their own ideas, top engineers often throw their weight behind their colleagues' projects, helping to bring them to fruition.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Collaborative Completion&lt;/strong&gt;: By reviewing pull requests, providing constructive feedback, and actively supporting peers, these engineers ensure that work reaches the finish line with high quality.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Making Tough Decisions&lt;/strong&gt;: Sometimes, finishing means knowing when to stop. Effective engineers aren't afraid to recommend cancelling work when it's clear that a chosen path is no longer viable, saving time and resources in the long run.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By prioritising completion, these engineers ensure that value is consistently delivered and that the team's efforts aren't wasted on half-finished projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Ensuring Growth for Those Around Them
&lt;/h2&gt;

&lt;p&gt;Great engineers are not just focused on their own development – they actively contribute to the growth of their entire team:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Educational Code Reviews&lt;/strong&gt;: When reviewing code, they go beyond surface-level comments. They provide in-depth feedback, often linking to relevant documentation or best practices, turning each review into a learning opportunity.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mentorship Through Pair Programming&lt;/strong&gt;: By engaging in pair programming sessions, especially with junior team members, top engineers share their problem-solving approaches and coding techniques in real-time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optimising Team Processes&lt;/strong&gt;: Whether it's introducing new methodologies or streamlining existing ones, these engineers constantly look for ways to improve how the team works together.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This focus on collective growth creates a rising tide that lifts all boats, resulting in a more skilled and efficient team overall.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Communicate Better Than Anyone Else
&lt;/h2&gt;

&lt;p&gt;Perhaps the most crucial pillar is communication. Highly effective engineers are outstanding communicators:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Transparent Thought Processes&lt;/strong&gt;: They don't just share results; they articulate their thinking, making their decision-making process clear to all stakeholders. This way assumptions can be tested earlier. Providing proactive status updates with potential risks or things you’re investigating further helps to build trust and gives others the opportunity to provide potential solutions or advice.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Setting Clear Expectations&lt;/strong&gt;: By communicating frequently and in detail, they ensure that everyone has a clear understanding of timelines, potential roadblocks, and project scope. This gives stakeholders the opportunity to raise any differences in expectations they might have early on, rather than further on in a project where changes may be more difficult to make.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Realistic Estimations&lt;/strong&gt;: While software development is inherently unpredictable, effective engineers provide the best possible estimates and clearly communicate the factors that might affect timelines. Delays and issues are best handled when shared early — if your stakeholders and peers know about issues, they might be able to help.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When engineers excel at communication, it reduces misunderstandings, allows for better decision-making across the organisation, and builds trust with stakeholders.&lt;/p&gt;

</description>
      <category>career</category>
      <category>webdev</category>
      <category>productivity</category>
    </item>
    <item>
      <title>The Multi-level Todo List</title>
      <dc:creator>Tom Butterwith</dc:creator>
      <pubDate>Mon, 22 Jan 2024 11:59:35 +0000</pubDate>
      <link>https://dev.to/tbutterwith/the-multi-level-todo-list-2hed</link>
      <guid>https://dev.to/tbutterwith/the-multi-level-todo-list-2hed</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally posted on &lt;a href="https://butterwith.space/blog/the-multi-level-todo-list"&gt;butterwith.space&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Since becoming a “lead of leads” I’ve found that a simple todo list of tasks no longer fits my needs. Given I spend most of my energy delegating tasks and following up on their progress later, I had tasks on my todo list that would be on there for weeks, sometimes months as they progressed. I also found that my attention was being pulled in a number of directions at once and I struggled to identify which tasks were important and how I should spend my time.&lt;/p&gt;

&lt;p&gt;There are a lot of words written about how to effectively manage todo lists, how to manage your time, how to prioritise, etc and I’m aware this adds to that massive pile &lt;em&gt;but&lt;/em&gt; I think it’s important to find a process that works for you. So here’s mine.&lt;/p&gt;

&lt;h3&gt;
  
  
  Weekly Goals
&lt;/h3&gt;

&lt;p&gt;This is the thing that keeps me on track when I’ve got multiple things on. Just like I would expect for a team, I set myself a one or two (never more) weekly goals which I use to help set direction for my week, and to help me measure if I’m making progress. I tend to set goals large enough to fill my week so that I’m somewhat stretched to complete them e.g. &lt;em&gt;Set up hiring pipeline for Senior Software engineer&lt;/em&gt; (which might include a number of meetings, writing a job spec, setting up and interview funnel) or if something is particularly important I might have a small task as goal to ensure it’s done that week e.g. &lt;em&gt;Set up 1:1s with new managers.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Any time I pick up a new task or have some down time, I refer back to my weekly goal. Does this task help me get closer to those goals? If not, then it goes to the bottom of my todo list.&lt;/p&gt;

&lt;p&gt;As the week progresses, I regularly check in on how I’m doing. If I’ve completed a goal I’ll mark it with a ✅. By the end of the week ideally both of my goals should be ticked, if not, I’ll mark any incomplete goals with ❌. I keep a record of all of my previous weekly goals and how I did so that I can look back over time and see a high-level summary of the work I’m doing.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Inbox
&lt;/h3&gt;

&lt;p&gt;The concept of an Inbox is from Getting Things Done by David Allen. This is a space to collect everything that you have on your mind at the moment, no matter how big or small. I use it as a scratch pad during meetings as well as a space to jot things down as I remember them so nothing gets lost. &lt;em&gt;Send a slack about project y&lt;/em&gt; – in the Inbox. &lt;em&gt;Define a process for incident debriefs&lt;/em&gt; – in the inbox. &lt;/p&gt;

&lt;p&gt;I like to go through my Inbox at the start and end of every day and, just like you would if you were running a team, triage anything that I’ve added over the course of the day. Anything that takes five minutes or less gets done there and then. If a task takes longer than that, it then gets moved into my Prioritised backlog.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Prioritised Backlog
&lt;/h3&gt;

&lt;p&gt;For me, the Prioritised Backlog is the key to keeping track of everything I have going on. Everything that was gathered in the Inbox is sorted into a item in the backlog, either a larger item that might hold a number of todos (such as a long running project with multiple steps) or on it’s own as a standalone task. If an item has more than one task in it I tend to keep a short summary at the top that reminds me what the latest status of that item is – in some cases a project I need to keep track of could run for multiple weeks where I don’t need to be actively involved.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2wl1gsvq2qjey6mkfaw3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2wl1gsvq2qjey6mkfaw3.png" alt="A screenshot the prioritised backlog template" width="800" height="462"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I’ve found I only need four categories for items on this board: Planning, Waiting on Others, In Progress and Done, with tasks regularly moving back and forth between In Progress and Waiting on Others.&lt;/p&gt;

</description>
      <category>productivity</category>
    </item>
    <item>
      <title>Nailing Your First Technical Interview</title>
      <dc:creator>Tom Butterwith</dc:creator>
      <pubDate>Wed, 16 Feb 2022 12:31:03 +0000</pubDate>
      <link>https://dev.to/tbutterwith/nailing-your-first-technical-interview-57p9</link>
      <guid>https://dev.to/tbutterwith/nailing-your-first-technical-interview-57p9</guid>
      <description>&lt;p&gt;The hunt for your first job can be a stressful time in your life. You’ve invested a huge amount of time and energy into learning the skills you think you need to start your journey in the world of professional software development, you’ve made some fantastic projects along the way, but who knows what those pesky interviewers are going to ask you in a “technical interview”.&lt;/p&gt;

&lt;p&gt;Well, a technical interview could mean a number of different things - an hour of questions, writing some code (either on a whiteboard or in an online editor), or a walk through one of your projects. What I intend to set out below are some topics to help you prepare what ever comes your way.&lt;/p&gt;

&lt;p&gt;🗒️ Throughout this page I’ll use the terms app, service or project interchangeably. What I mean by this is a &lt;em&gt;thing&lt;/em&gt; of some kind that you’ve built.&lt;/p&gt;

&lt;p&gt;Let’s start with the project walkthrough and some of the areas you might want to touch on. The topics below are also a great starting point for “an hour of questions” style interviews.&lt;/p&gt;




&lt;h2&gt;
  
  
  “Tell me about your project”
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;This style of interview requires you to think about a project that you’ve worked on and answer questions on the design and implementation.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;First things first, how do you decide which of your projects you should chose? When I’m interviewing I’m really looking for a project that fits two criteria:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Is this project complex enough to cover all of the areas I need to cover?
The project might not cover more complex topics like deployment or scale, but we need to be able to have a discussion about this in a hypothetical way. “If this app went viral, what’s the first thing that would break?”&lt;/li&gt;
&lt;li&gt;Are you able to talk about every part of this project, whether you worked directly on it or not?
You don’t need to have built the entire project you’re talking through, but you do need to be able to talk through how it works and why certain decisions were made. You may have built the front-end but you need to know about the database and back-end (and visa versa).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you find yourself building lots of “hello world” or todo list apps to show your versatility in learning frameworks or languages, a better investment with your time might be to create a single, more complex application so you can show your depth.&lt;/p&gt;

&lt;p&gt;So, you’ve picked a project that you’re happy talking about in depth - what sort of topics should you prepare?&lt;/p&gt;




&lt;h2&gt;
  
  
  Design decisions
&lt;/h2&gt;

&lt;p&gt;Most of the questions in this area will be around why you made certain choices when building your application. You may not have considered any of these things when designing your application so it’s a good idea to retrospectively review some decisions you may have made. “Because this is the technology I know” is an &lt;em&gt;alright&lt;/em&gt; answer, but companies will be looking for candidates that are able to see how the tools and technology they know fit into a wider ecosystem. There are a million and one frameworks and tools to solve a problem so you’re going to need to know how to pick the one that fits the job best.&lt;/p&gt;

&lt;p&gt;I’ve included a non-exhaustive list of questions below, some may not be applicable to your project depending on its design. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;“Why did you chose language &lt;em&gt;x&lt;/em&gt; over &lt;em&gt;y&lt;/em&gt;?”&lt;/li&gt;
&lt;li&gt;“Why did you use a SQL database over NoSQL?” (or vice versa)&lt;/li&gt;
&lt;li&gt;“Why is the database structured the way it is? How do the relationships between entities work?”&lt;/li&gt;
&lt;li&gt;“Why do you have a server between your client and your database? What are the advantages of this?”&lt;/li&gt;
&lt;li&gt;“How does your application deal with failures?” - I personally like this one as it allows you to talk about how people might use your app and what kind of experience you want them to have when things don’t quite work out&lt;/li&gt;
&lt;li&gt;“Why did you use &lt;em&gt;x&lt;/em&gt; front end framework? What advantages does it bring over plain/vanilla JS and HTML?”&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Testing
&lt;/h2&gt;

&lt;p&gt;If you’ve learnt to programme via a bootcamp or you’re self-taught you may have never &lt;em&gt;needed&lt;/em&gt; to write tests but you’ve probably had a lesson or two covering them. Testing is a really important tool for ensuring the software you write:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Works in the way that you intended&lt;/li&gt;
&lt;li&gt;Interacts with other services and other software&lt;/li&gt;
&lt;li&gt;Doesn’t break when someone else (or even you) comes to make changes later&lt;/li&gt;
&lt;li&gt;Is easy to understand&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It’s my opinion that you don’t need to have written tests to get your first job, but you should have an understanding of why they are important and an idea of the different types of testing. A couple of key questions to answer would be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;“What value do tests provide?”&lt;/li&gt;
&lt;li&gt;“How might you stop the next contributor to your service breaking what you’ve written?”&lt;/li&gt;
&lt;li&gt;“How do you know the code you’ve written works as expected?”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A few types of tests to look into at unit tests, acceptance tests, integration tests, and performance tests.&lt;/p&gt;

&lt;p&gt;Lastly, one often overlooked use of tests is to document your code. Unit tests can often provide information on the way a method is expected to be used and the kind of data the original programmer anticipated might be used. Next time you’re trying to understand someone else’s code, take a look at the tests.&lt;/p&gt;




&lt;h2&gt;
  
  
  Scale
&lt;/h2&gt;

&lt;p&gt;Depending on the type of applications you’ve written, you may have never had to think about scale. Code running on even the most basic laptop can support enough users to test your code, share with friends, and potentially even publish to the internet. Writing software for a business will take you beyond that and it’s important that you know how to think about scaling software.&lt;/p&gt;

&lt;p&gt;The best place to start when thinking about performance is to look at your application and try to work out which part will break first. Will your server manage with 100 times the number of requests it’s got at the moment? What about 1000 times? How about your database? Focus in on the weakest part of your application and how might you improve its capacity.&lt;/p&gt;

&lt;p&gt;To scale an application there are two main approaches:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Vertical scaling:&lt;/strong&gt; this is the simplest form of scaling and it involves increasing the power of the machine your code is running on. Got 500Mb of RAM? Make it 1Gb. This is useful for parts of your application that store data (or manage state as some people would refer to it.) It’s the easiest way to add capacity without too much difficultly. A word of caution with this approach - you can only go so big before cost becomes the prohibitive factor.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Horizontal scaling:&lt;/strong&gt; this involves running multiple copies (or instances) of your code on replica machines. Have one server running your back-end? Try two. This is a really effective way of splitting the load across different instances. When horizontally scaling your application you’ll need to think about balancing the load on each machine, and handily there are services called Load Balancers to do exactly that for you. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Similarly to the point on testing, I wouldn’t expect early career candidates to have experience in scaling an application but understanding &lt;strong&gt;how&lt;/strong&gt; software scales is important to know.&lt;/p&gt;




&lt;h2&gt;
  
  
  Deploying Software
&lt;/h2&gt;

&lt;p&gt;Lastly. you should be aware of how to deploy software. Like the other sections, a surface understanding of the type of services you might use to get your application in front of users. Here’s a short list of topics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Version control:&lt;/strong&gt; All good deployment pipelines start with source control. You should understand why git and version control in general are good ideas&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Continuous deployment&lt;/strong&gt;: When committing to master, how does your traffic serving service get updated? Tools like Netlify and Heroku have this build in, services like Jenkins and Github Actions provide more customisation&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Infrastructure&lt;/strong&gt;: What’s running your service? Things to look at here include EC2 instances (or other cloud provisioned virtual machines), cloud database providers like Dynamo DB or Azure Database.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Logging and alerting&lt;/strong&gt;: How do you know when your app has stopped working? Relying on users to contact you is one way but that’s often not the best idea. Tools like Loggly, NewRelic, and LogRocket allow you to find out automatically when something isn’t working as it should and help you get to the bottom of it.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;In short, the points above should take you beyond thinking about writing code and into the other problems you’ll face running software at scale. Take all of this with a pinch of salt. Not every company is going to ask you the same questions and have the same expectations of a junior engineer, but understanding how to get your code, your apps, your products in front of people is very powerful knowledge indeed.&lt;/p&gt;

&lt;p&gt;Best of luck, you’re just getting started on an exciting and potentially rewarding journey! 🚀&lt;/p&gt;




&lt;p&gt;For more of my writing, see &lt;a href="https://butterwith.space/blog"&gt;https://butterwith.space/blog&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>interviewing</category>
      <category>jobs</category>
    </item>
    <item>
      <title>Your Voice Matters</title>
      <dc:creator>Tom Butterwith</dc:creator>
      <pubDate>Thu, 13 Jan 2022 15:22:29 +0000</pubDate>
      <link>https://dev.to/tbutterwith/your-voice-matters-136l</link>
      <guid>https://dev.to/tbutterwith/your-voice-matters-136l</guid>
      <description>&lt;p&gt;I’ve been leading teams for a couple of years now and I often receive feedback from my direct reports that they’re either unsure on how best to contribute to team discussions, or they’re newer senior engineers and don’t understand the weight their voice carries in discussions. What you’ll find below are some examples of how you can use your voice to benefit the team regardless of your role, and a couple of pitfalls to watch out for as you become more senior.&lt;/p&gt;

&lt;h3&gt;
  
  
  Junior Developer
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;An early career software developer - between 0 and 12 months experience.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Being a junior developer is an opportunity you only really get once. Question everything. Why are you using this framework over that one, what does that acronym mean, why is &lt;em&gt;this&lt;/em&gt; &lt;em&gt;thing&lt;/em&gt; important? These questions are expected and should be utilised to the fullest, for both your own benefit and that of you team. Just like a new joiner to a team (which you are as well as a junior developer) you have an unjaded viewpoint from which to objectively question any and all processes.&lt;/p&gt;

&lt;p&gt;Honestly questioning existing processes and tools causes the team to reevaluate their choices up until now. Does this service/process/tool still provide value? Can I justify why this exists? Do I understand this thing enough to explain it to someone new? Anything that doesn’t have clear benefits or can’t be explained fully should be followed up on by the team later - either it’s no longer adding the value it once did, or there’s a gap in understanding that should be filled in.&lt;/p&gt;

&lt;h3&gt;
  
  
  New Joiners
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;A developer that has just changed team - any level of experience.&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;📢 Note: If you haven’t changed domain or looked for new opportunities in the last two years, this is a reminder to do so. You’ll benefit immensely from taking your experience and applying it to a new problem. Likewise, the problem you work on next will benefit from a new perspective and different experience. This often doesn’t need to be a job change, in fact you’ll often benefit from a rotation inside your current workplace.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Welcoming new members to a team is a great way of reevaluating the current stack and processes (see the previous section) as well as injecting a new viewpoint into discussions. You have the opportunity to input into discussions without carrying the baggage of previous work. “We tried that before and we can’t do this because of &lt;em&gt;x&lt;/em&gt;”, “Vendor &lt;em&gt;y&lt;/em&gt; doesn’t want to do &lt;em&gt;z&lt;/em&gt;” etc. Things change, problems evolve, existing tools become obsolete and are replaced by new ones, so why not reevaluate some decisions that were made in that past. &lt;/p&gt;

&lt;p&gt;This is your opportunity to ask questions of your new teammates, both to gain context on the decisions that have gone before and to challenge the status quo. Pairing with a member of the team on some of these opportunities is a great way to get to know your area of the business better and build bonds with the team.&lt;/p&gt;

&lt;h3&gt;
  
  
  Senior Developer
&lt;/h3&gt;

&lt;p&gt;As a senior developer your voice carries more weight than you might realise, especially if you've recently been promoted. Other members of the team will look to you for feedback on their ideas - both explicitly by asking for it, and implicitly by listening to how you react to the things they're talking about. Junior engineers may follow your lead without realising it as they learn what it means to be a software engineer. Before contributing to discussions you need to be aware of how your ideas are perceived.&lt;/p&gt;

&lt;p&gt;In general, I encourage senior engineers to speak last. This helps to avoid &lt;a href="[https://thedecisionlab.com/biases/anchoring-bias/](https://thedecisionlab.com/biases/anchoring-bias/)"&gt;anchoring bias&lt;/a&gt; and provide space for less senior engineers to voice their thoughts. It’s much easier for you to critique them than it is for them to critique you.&lt;/p&gt;

&lt;p&gt;This isn’t to say you shouldn’t feel comfortable contributing to discussions first, you just need to pick your moments. If there is a decision you feel strongly about, or is potentially high impact, then that’s the time to use your influence to reinforce your point.&lt;/p&gt;




&lt;p&gt;For more of my writing, see &lt;a href="https://butterwith.space/blog"&gt;https://butterwith.space/blog&lt;/a&gt;&lt;/p&gt;

</description>
      <category>communication</category>
      <category>management</category>
      <category>career</category>
    </item>
    <item>
      <title>Refactor your if statements for improved readability</title>
      <dc:creator>Tom Butterwith</dc:creator>
      <pubDate>Thu, 04 Mar 2021 17:16:11 +0000</pubDate>
      <link>https://dev.to/tbutterwith/refactor-your-if-statements-for-improved-readability-1l8</link>
      <guid>https://dev.to/tbutterwith/refactor-your-if-statements-for-improved-readability-1l8</guid>
      <description>&lt;p&gt;As I write more software and mature as an engineer, I've begun to understand that &lt;em&gt;less&lt;/em&gt; code isn't always &lt;em&gt;better&lt;/em&gt; code. Although the code we write is for machines to understand, it's often compiled and optimised for them before it's run. It's much more valuable to write code that's easier for people to understand - it leads to faster code reviews, less confusion, and safer code as people can easily see the intentions behind your code as well as what it does.&lt;/p&gt;

&lt;p&gt;With this in mind, I've recently started writing &lt;code&gt;if&lt;/code&gt; statements differently, trying to make the condition statements as legible as possible. One technique I've found particularly useful is moving the conditional statement into its own function.&lt;/p&gt;

&lt;p&gt;Consider this if statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;statusCode&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;statusCode&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bad response&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's quite obvious that this &lt;code&gt;if&lt;/code&gt; statement checks for error code, but what if I'm not familiar with the exact error codes that should be considered an error or the list of 'bad' codes grows? We could refactor this &lt;code&gt;if&lt;/code&gt; statement into it's own function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isBadResponseCode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;statusCode&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;statusCode&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;statusCode&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;isBadResponseCode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;statusCode&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bad response&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The gains here are two-fold. Firstly,  it's crystal clear what we're looking for in that &lt;code&gt;if&lt;/code&gt; statement and when we should trigger the condition - bad response codes. If I'm skim-reading the code to get a feel for what it does, I don't need to consider exactly which response codes are bad, just that the program does something if it receives one.&lt;/p&gt;

&lt;p&gt;Secondly, the response code comparison is contained within its own function which means it's easier to read in isolation. I don't need to break down the &lt;code&gt;if&lt;/code&gt; statement to review which response codes the program considers 'bad'.&lt;/p&gt;

&lt;p&gt;This is an oversimplification of this concept but it helps to prove a point. We've added more lines of code but I would argue that we've made it easier to understand and reason about, and self-documenting.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>python</category>
      <category>java</category>
      <category>refactoring</category>
    </item>
    <item>
      <title>Avoid Magic Numbers to Increase Code Readability</title>
      <dc:creator>Tom Butterwith</dc:creator>
      <pubDate>Wed, 03 Mar 2021 17:29:33 +0000</pubDate>
      <link>https://dev.to/tbutterwith/avoid-magic-numbers-to-increase-code-readability-1da1</link>
      <guid>https://dev.to/tbutterwith/avoid-magic-numbers-to-increase-code-readability-1da1</guid>
      <description>&lt;h3&gt;
  
  
  What are magic numbers?
&lt;/h3&gt;

&lt;p&gt;Magic numbers are any numeric constant declared in your code. They could help you convert minutes to seconds, set limits for the number of all records in a database, or repeat a process a constant number of times. In any case, you'll see things like &lt;code&gt;for(const i = 0; i &amp;lt; 10; i++)&lt;/code&gt; or &lt;code&gt;return x * 60&lt;/code&gt;. &lt;/p&gt;

&lt;h3&gt;
  
  
  Why should you avoid them?
&lt;/h3&gt;

&lt;p&gt;On their own, these numbers carry no explicit meaning, the developer has to &lt;em&gt;infer&lt;/em&gt; what they are from the context they are used. This might be easy, everyone knows there are 60 seconds in a minute. Others, like the example for converting kilometres to miles below, are more obscure. &lt;/p&gt;

&lt;h3&gt;
  
  
  What should you do instead?
&lt;/h3&gt;

&lt;p&gt;Consider this example. On its own, &lt;code&gt;0.6213712&lt;/code&gt; carries very little meaning. We can establish from the method name that this might be the number of miles in a kilometre but without looking it up or a code comment, we can only assume. &lt;/p&gt;

&lt;p&gt;By giving this value its own variable with a helpful name, we're writing self-documenting code that gives the next person to read this code all the information they need to know exactly what a value is.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example one&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Before: large float in the middle of a function&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;convertKilometersToMiles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;distanceInKm&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;distanceInKm&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.6213712&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// After: The function is easier to read at a glace. &lt;/span&gt;
&lt;span class="c1"&gt;// Anyone reviewing the code can clearly see the intent of the function&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MILES_IN_KILOMETER&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.6213712&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;convertKilometersToMiles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;distanceInKm&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;distanceInKm&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;MILES_IN_KILOMETER&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example two&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Before&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;too many users&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// After&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;CONCURRENT_USER_LIMIT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;CONCURRENT_USER_LIMIT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;too many users&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>refactoring</category>
      <category>python</category>
      <category>java</category>
    </item>
    <item>
      <title>Dependency Injection in Java with Guice</title>
      <dc:creator>Tom Butterwith</dc:creator>
      <pubDate>Sun, 19 Jul 2020 11:59:29 +0000</pubDate>
      <link>https://dev.to/tbutterwith/dependency-injection-in-java-with-guice-51pk</link>
      <guid>https://dev.to/tbutterwith/dependency-injection-in-java-with-guice-51pk</guid>
      <description>&lt;p&gt;This post is designed as an overview and reference guide to the different methods of using dependency injection in Java. For in-depth documentation and the background context around the Guice library see the &lt;a href="https://github.com/google/guice/wiki"&gt;official Guice documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is DI?
&lt;/h2&gt;

&lt;p&gt;Dependency Injection (DI) is a design pattern. Its core principle is to separate behaviour from dependency resolution. This means your classes should only have to deal with their function, and not have to consider where their dependencies are coming from.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use DI?
&lt;/h2&gt;

&lt;p&gt;DI is useful for two main reasons. Firstly, it enables you to write loosely coupled classes. As dependencies are resolved by a central mechanism, there are no ties to a factory or provider class that will instantiate your dependencies. Dependency management is now configured in a single place, in this case using Guice and Modules.&lt;/p&gt;

&lt;p&gt;Secondly, injected dependencies are easy to mock making your loosely coupled classes easier to test. As you'll see later on, mocking what were once complex dependencies is as simple as using the &lt;code&gt;@Mock&lt;/code&gt; annotation and passing them to the constructor.&lt;/p&gt;

&lt;h2&gt;
  
  
  All examples are for Guice
&lt;/h2&gt;

&lt;p&gt;As the heading says, all of the examples in this post use Guice for dependency resolution. Guice is an industry-standard Java library for implementing DI and widely used and well documented online. Let's get right into.&lt;/p&gt;

&lt;h2&gt;
  
  
  Application Setup
&lt;/h2&gt;

&lt;p&gt;In the simplest instance, Guice is configured using a single &lt;code&gt;AbstractModule&lt;/code&gt; and a statically generated injector. With these 8 lines, you can create an injector and fetch instances of any configured class within your application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;MyModule&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;AbstractModule&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@override&lt;/span&gt;
    &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;configure&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Write your bindings for interfaces here e.g.&lt;/span&gt;
        &lt;span class="n"&gt;bind&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;IMyInterface&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MyInterfaceImpl&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Injector&lt;/span&gt; &lt;span class="n"&gt;injector&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Guice&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;createInjector&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;MyModule&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
    &lt;span class="c1"&gt;// Injected instance of MyClass.&lt;/span&gt;
    &lt;span class="nc"&gt;MyClass&lt;/span&gt; &lt;span class="n"&gt;myClass&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;injector&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getInstance&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MyClass&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Injecting Dependencies via Constructor Arguments (Recommended Approach)
&lt;/h2&gt;

&lt;p&gt;This is the simplest example of dependency injection. &lt;code&gt;MyInjectedClass&lt;/code&gt; has a no-arguments constructor so it can be injected into &lt;code&gt;MyClass&lt;/code&gt; without any setup. Guice will fetch a new instance of  &lt;code&gt;MyInjectedClass&lt;/code&gt; - no need for a factory class or &lt;code&gt;new MyInjectectedClass();&lt;/code&gt; . &lt;code&gt;@Inject&lt;/code&gt; lets Guice know that the constructor parameters should be resolved using DI.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;MyInjectedClass&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="o"&gt;...&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt; 

&lt;span class="nd"&gt;@Inject&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;MyClass&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MyInjectedClass&lt;/span&gt; &lt;span class="n"&gt;injectedClass&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="o"&gt;...&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If your injected class has dependencies, annotate that class with the &lt;code&gt;@Inject&lt;/code&gt; annotation. Guice will recursively fetch the required instances until it reaches a no-argument constructor or all dependencies have been satisfied.&lt;/p&gt;

&lt;h2&gt;
  
  
  Injecting Field Dependencies.
&lt;/h2&gt;

&lt;p&gt;Instead of using constructor arguments, dependencies can be injected directly to a field. This is the most concise form of injection but is difficult to test (testing constructor injection is covered below.)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DemoClass&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@Inject&lt;/span&gt;
    &lt;span class="nc"&gt;MyClass&lt;/span&gt; &lt;span class="n"&gt;instanceOfMyClass&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;DemoClass&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// NOTE THAT instanceOfMyClass will be null here&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="n"&gt;bool&lt;/span&gt; &lt;span class="nf"&gt;hasMyClass&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;instanceOfMyClass&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One thing to note about field injection is that &lt;strong&gt;the field will not be instantiated inside the constructor&lt;/strong&gt;. If you need the field to be instantiated in the constructor you must use constructor injection.&lt;/p&gt;

&lt;h2&gt;
  
  
  DI for Static Dependencies
&lt;/h2&gt;

&lt;p&gt;You might find yourself migrating parts of an older project from static factories to dependancy injection and you need to grab an instance of a class set up for DI in a static class. No problem. You can configure Guice to set up your static classes at injector-creation time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Override the configure() method of your module&lt;/span&gt;
&lt;span class="nd"&gt;@Override&lt;/span&gt; 
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;configure&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;requestStaticInjection&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MyStaticClass&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;...&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyStaticClass&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@Inject&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;MyClass&lt;/span&gt; &lt;span class="n"&gt;instanceOfMyClass&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using the Provides Annotation
&lt;/h2&gt;

&lt;p&gt;If your class requires some set up, you might want to create a &lt;code&gt;@Provides&lt;/code&gt; annotated method inside your module. This allows you to run some code or provide some configuration when instantiating a class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Provides&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;MyClass&lt;/span&gt; &lt;span class="nf"&gt;providesMyClass&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;MyClass&lt;/span&gt; &lt;span class="n"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;MyClass&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setSomeValue&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"cool"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Named Annotation
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;@Named&lt;/code&gt; annotation allows you to identify a specific instance of a class. This is required by Guice if you have more than one instance of a class - very handy if you connect to multiple databases or caches using the same wrapper class, just set up a &lt;code&gt;@Named&lt;/code&gt; provider for each one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Provides&lt;/span&gt;
&lt;span class="nd"&gt;@Named&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"SpecialInstanceOfMyClass"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;MyClass&lt;/span&gt; &lt;span class="nf"&gt;providesMyClass&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;MyClass&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="nd"&gt;@Inject&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;SomeOtherClass&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nd"&gt;@Named&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"SpecialInstanceOfMyClass"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nc"&gt;MyClass&lt;/span&gt; &lt;span class="n"&gt;instanceOfMyClass&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="o"&gt;...&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Binding Interfaces to Implementations
&lt;/h3&gt;

&lt;p&gt;Guice needs to be told how to implement interfaces. As with the set up example at the beginning of this post, interfaces can be bound to their implementations inside a module.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;MyModule&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;AbstractModule&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@override&lt;/span&gt;
    &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;configure&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Write your bindings for interfaces here e.g.&lt;/span&gt;
        &lt;span class="n"&gt;bind&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;IMyInterface&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MyInterfaceImpl&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;bind&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;IOtherInterface&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;OtherImplementation&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Configuring Multiple modules
&lt;/h3&gt;

&lt;p&gt;If you find your module is becoming large, or you want to separate concerns into different files for readability, you can register multiple modules with Guice. Be careful not to register the same dependency in more than one module - Guice will remind you with a helpful compiler exception.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Injector&lt;/span&gt; &lt;span class="n"&gt;injector&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Guice&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;createInjector&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;MyModule&lt;/span&gt;&lt;span class="o"&gt;(),&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;OtherModule&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Automatically bound things
&lt;/h2&gt;

&lt;p&gt;Some frameworks are configured for Guice out of the box and will automatically bind providers for interfaces. For example Dropwizard will automatically bind instances of the &lt;code&gt;Managed&lt;/code&gt; interface - any implementations you attempt to register in your module will throw an exception.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing
&lt;/h2&gt;

&lt;p&gt;The great thing about dependency injection is it makes your dependencies easy to mock and your tests simple to write. Imagine the following class with two dependencies injected into the constructor:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyExampleClass&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;DBClient&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;CacheClient&lt;/span&gt; &lt;span class="n"&gt;cache&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="nd"&gt;@Inject&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;MyExampleClass&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;DBClient&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;CacheClient&lt;/span&gt; &lt;span class="n"&gt;cache&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;cache&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cache&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using the &lt;code&gt;@Mock&lt;/code&gt; annotation, we can get Mockito to create a mock version of each of the dependencies with no extra set up. These can be passed into our constructor to be used later. An example test file might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@RunWith&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MockitoJUnitRunner&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyExampleClassTest&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@Mock&lt;/span&gt;
    &lt;span class="nc"&gt;DBClient&lt;/span&gt; &lt;span class="n"&gt;mockClient&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nd"&gt;@Mock&lt;/span&gt;
    &lt;span class="nc"&gt;CacheClient&lt;/span&gt; &lt;span class="n"&gt;mockCache&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="nc"&gt;MyExampleClass&lt;/span&gt; &lt;span class="n"&gt;myClass&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="nd"&gt;@BeforeEach&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setup&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;myClass&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;MyClass&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mockClient&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mockCache&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nd"&gt;@Test&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;myTest&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Use the static Mockito.when() method to set up your mocks&lt;/span&gt;
        &lt;span class="n"&gt;when&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mockClient&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;connect&lt;/span&gt;&lt;span class="o"&gt;()).&lt;/span&gt;&lt;span class="na"&gt;thenReturn&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Connection&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
        &lt;span class="n"&gt;myClass&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;someFunction&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Creating an injector and binding classes
&lt;/h3&gt;

&lt;p&gt;Finally, if you're using Field Injection and you need to mock that dependency you can set up your tests as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@RunWith&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MockitoJUnitRunner&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyExampleClassTest&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@Mock&lt;/span&gt;
    &lt;span class="nc"&gt;MyFieldDependency&lt;/span&gt; &lt;span class="n"&gt;mockDependency&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="nd"&gt;@BeforeEach&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setup&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;injector&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Guice&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;createInjector&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AbstractModule&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="nd"&gt;@Override&lt;/span&gt;
            &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;configure&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;bind&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MyFieldDependency&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;toInstance&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mockDependency&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;});&lt;/span&gt;
        &lt;span class="n"&gt;myClass&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;injector&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getInstance&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MyClass&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nd"&gt;@Test&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;myTest&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Use the static Mockito.when() method to set up your mocks&lt;/span&gt;
        &lt;span class="n"&gt;when&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mockDependency&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;something&lt;/span&gt;&lt;span class="o"&gt;()).&lt;/span&gt;&lt;span class="na"&gt;thenReturn&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;myClass&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;someFunction&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tells Guice to fetch an instance of &lt;code&gt;MyClass&lt;/code&gt; and to use &lt;code&gt;mockDependency&lt;/code&gt; to resolve the injected field &lt;code&gt;MyFieldDependancy&lt;/code&gt;.&lt;/p&gt;

</description>
      <category>java</category>
      <category>designpatterns</category>
      <category>guice</category>
    </item>
    <item>
      <title>Do you consider the environmental impact of your software?</title>
      <dc:creator>Tom Butterwith</dc:creator>
      <pubDate>Mon, 22 Jul 2019 15:48:50 +0000</pubDate>
      <link>https://dev.to/tbutterwith/do-you-consider-the-environmental-impact-of-your-software-keg</link>
      <guid>https://dev.to/tbutterwith/do-you-consider-the-environmental-impact-of-your-software-keg</guid>
      <description>&lt;p&gt;When writing or deploying software, do you consider the environmental impact of it? Does this factor into the design process when choosing hosting etc?&lt;/p&gt;

&lt;p&gt;I've been thinking about this more and more lately as cloud computing environments have started posting their emissions statistics. For example &lt;a href="https://cloud.google.com/sustainability/"&gt;Google are 100% carbon neutral&lt;/a&gt;, AWS is 50% neutral &lt;a href="https://aws.amazon.com/about-aws/sustainability/"&gt;with a promise to go 100%&lt;/a&gt;, and Microsoft are &lt;a href="https://blogs.microsoft.com/on-the-issues/2019/04/15/were-increasing-our-carbon-fee-as-we-double-down-on-sustainability/"&gt;doubling down on sustainability&lt;/a&gt;&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>aws</category>
      <category>google</category>
      <category>microsoft</category>
    </item>
    <item>
      <title>Alfred and Dash: improving your workflow</title>
      <dc:creator>Tom Butterwith</dc:creator>
      <pubDate>Thu, 11 Jul 2019 13:49:46 +0000</pubDate>
      <link>https://dev.to/tbutterwith/alfred-and-dash-improving-your-workflow-50nj</link>
      <guid>https://dev.to/tbutterwith/alfred-and-dash-improving-your-workflow-50nj</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fdf3ag6nh960p09mgspc4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fdf3ag6nh960p09mgspc4.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Alfred
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Alfred is an award-winning app for Mac OS X which boosts your efficiency with hotkeys, keywords, text expansion and more.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The above statement is taken directly from the &lt;a href="https://www.alfredapp.com/" rel="noopener noreferrer"&gt;Alfred website&lt;/a&gt;, but it only scratches the surface of what Alfred can do. Besides the search functionality, the ability to integrate with other applications is a real game changer for increasing your efficiency.&lt;br&gt;
On it's own, Alfred is a Spotlight search replacement but it really shines when you add in the &lt;a href="https://www.alfredapp.com/powerpack/" rel="noopener noreferrer"&gt;Powerpack&lt;/a&gt; allowing you to write your own workflows and integrate fully with other applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dash
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Dash is an API Documentation Browser and Code Snippet Manager.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Using Dash has been one of the biggest optimisations in my programming career. Being able to search through local copies of documentation and "cheat sheets" rather than opening a web browser and searching for what I'm looking for.&lt;br&gt;
Not only does Dash store doc sets, it has the ability to store code snippets, which can be tagged to aid searchability. These code snippets can then be used in other applications thanks to it's autocomplete feature. This is really handy for storing code templates, letting you think about writing feature code and not boiler plate.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fr3iznozik729s35amodj.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fr3iznozik729s35amodj.gif"&gt;&lt;/a&gt;&lt;/p&gt;
Example text expansion from Dash in VS Code



&lt;h2&gt;
  
  
  Workflows
&lt;/h2&gt;

&lt;p&gt;Workflows allow you to add cross application functionality to Alfred, enabling more complex tasks and allowing you to automate a number of repetitive tasks. There are a number of these available through the Alfred website but I'm going to be focusing on the &lt;a href="https://www.alfredapp.com/blog/productivity/dash-quicker-api-documentation-search/" rel="noopener noreferrer"&gt;Dash integration&lt;/a&gt; as that's what I have found most useful.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fsa8vuvxvjc3g6hhtyf86.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fsa8vuvxvjc3g6hhtyf86.png"&gt;&lt;/a&gt;&lt;/p&gt;
The available Alfred Workflows



&lt;p&gt;Provided you have the Alfred powerpack and Dash installed, the workflow is available in the preferences section of Dash.&lt;/p&gt;

&lt;p&gt;After double clicking the Alfred icon, the workflow should install it's self.&lt;/p&gt;

&lt;h2&gt;
  
  
  Customising your docsets
&lt;/h2&gt;

&lt;p&gt;Under the Downloads section of the Dash preference pane, there are a number of both official and user contributed doc sets available for download. There is a handy search bar that allows you to search across all of the docsets for any particular set you're looking for.&lt;br&gt;
Once installed, the keyword for searching a docset can be customised using the Docsets prefenence pane. The shorter the search term, the faster Alfred will recognise you're searching for a keyword within Dash.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fq2ineumdip1vjvp6qe2t.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fq2ineumdip1vjvp6qe2t.gif"&gt;&lt;/a&gt;&lt;/p&gt;
Quick Access React Documentation



</description>
      <category>workflow</category>
      <category>javascript</category>
      <category>python</category>
    </item>
    <item>
      <title>Asynchronous Javascript: 3 ways</title>
      <dc:creator>Tom Butterwith</dc:creator>
      <pubDate>Wed, 10 Jul 2019 11:29:36 +0000</pubDate>
      <link>https://dev.to/tbutterwith/asynchronous-javascript-3-ways-17i2</link>
      <guid>https://dev.to/tbutterwith/asynchronous-javascript-3-ways-17i2</guid>
      <description>&lt;h2&gt;
  
  
  Callbacks, Promises, and Async/Await
&lt;/h2&gt;

&lt;p&gt;The JavaScript engine is single threaded and utilises an event loop. Simply put, this means any statements you run will be executed one after the other in a single process. To avoid blocking calls, there are a number of techniques that JavaScript employs to avoid waiting while something is computed. These are &lt;strong&gt;asynchronous functions&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You can read more about the event loop &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop"&gt;here&lt;/a&gt; as the topic is too deep to cover in this post.&lt;/p&gt;

&lt;p&gt;JavaScript provides three methods of handling asynchronous code: callbacks, which allow you to provide functions to call once the asynchronous method has finished running; promises, which allow you to chain methods together; and async/await keywords, which are just some syntactic sugar over promises.&lt;/p&gt;

&lt;h3&gt;
  
  
  Callbacks
&lt;/h3&gt;

&lt;p&gt;The original method of handling asynchronicity. Callbacks allow you to provide a function to be executed &lt;strong&gt;after&lt;/strong&gt; the asynchronous code has finished. In the example below, &lt;code&gt;functionWithACallback&lt;/code&gt; takes a function as an argument and will call that function when it is finished.&lt;/p&gt;

&lt;p&gt;This method, passing functions back and forth, can become very confusing if you need to chain a number of these calls together. The callback will need to be passed down the execution chain to be called at the end of the final process.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;functionWithACallback&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;//do some work then call the callback once done&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;You called this function!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I am done&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// the function we want to call when the work is done&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myCallback&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;
  &lt;span class="c1"&gt;// this will call myCallback once it is finished &lt;/span&gt;
  &lt;span class="nf"&gt;functionWithACallback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myCallback&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nf"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;//  You called this function&lt;/span&gt;
&lt;span class="c1"&gt;//  I am done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Promises
&lt;/h3&gt;

&lt;p&gt;One of the main problems with callbacks is, when chaining a number of function calls together it can become increasingly difficult to follow the flow of execution. Promises aim to solve this issue by allowing you to chain together promises using the &lt;code&gt;.then()&lt;/code&gt; syntax. The example below works the same way as the callback example, but is much easier to follow: wait till &lt;code&gt;getPromise()&lt;/code&gt; has completed and &lt;strong&gt;then&lt;/strong&gt; call the function containing &lt;code&gt;console.log()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Error handling with promises is also less complex. Rather than calling the callback with an error object, promises provide a &lt;code&gt;.catch()&lt;/code&gt; wrapper to help manage error states. Below, the &lt;code&gt;catch&lt;/code&gt; block will be executed if an error occurs in any of the promises above it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getPromise&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;My return value&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;getPromise&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// prints 'My return value'&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="c1"&gt;// If there is an error in any of the above promises, catch&lt;/span&gt;
       &lt;span class="c1"&gt;// it here&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;   
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Async/Await
&lt;/h3&gt;

&lt;p&gt;In the more recent versions of JavaScript, the &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;await&lt;/code&gt; keywords were added. This provides a cleaner method of writing promises and gives the user more control over execution order. The below example is identical to the promises example in functionality, but is written using the &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;await&lt;/code&gt; keywords.&lt;br&gt;
Error handling for &lt;code&gt;async&lt;/code&gt; function calls is provided using a &lt;code&gt;try/catch&lt;/code&gt; block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getPromise&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;My return value&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// the function is marked with the async keyword&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;  
  &lt;span class="c1"&gt;// tell the interpreter we want to wait on the response&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;val&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getPromise&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="c1"&gt;// execute when the promise above is resolved&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// prints 'My return value'&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Jupyter Notebooks for Software Engineers 🚀</title>
      <dc:creator>Tom Butterwith</dc:creator>
      <pubDate>Tue, 09 Jul 2019 11:59:23 +0000</pubDate>
      <link>https://dev.to/tbutterwith/jupyter-notebooks-for-software-engineers-18m5</link>
      <guid>https://dev.to/tbutterwith/jupyter-notebooks-for-software-engineers-18m5</guid>
      <description>&lt;p&gt;Jupyter Notebook is an interactive web application that interfaces with the iPython repl, allowing you to run structured but iterative Python scripts. It is the de facto choice for data scientists to rapidly prototype pipelines, visualise data, or perform ad hoc analysis.&lt;/p&gt;

&lt;p&gt;Jupyter notebooks are a fantastic way to visual any data sets you might have, as well and conduct ad hoc analysis. &lt;strong&gt;It is especially useful for querying databases and displaying the data in a repeatable manner.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up Your Environment
&lt;/h2&gt;

&lt;p&gt;When working on any python project, I like to use Pyenv and the Pyenv Virtual Environment wrapper to manage all of the different python versions and dependencies. You can find the installation guides for on the &lt;a href="https://github.com/pyenv/pyenv#installation"&gt;Pyenv GitHub repo&lt;/a&gt; and the &lt;a href="https://github.com/pyenv/pyenv-virtualenv#installation"&gt;Virtual Env wrapper&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you don't have Python 3.6 installed already run the following:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;pyenv &lt;span class="nb"&gt;install &lt;/span&gt;3.6.0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Setup a new virtual environment and activate it:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Create a Python 3.6.0 environment called jupyter-notebooks&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;pyenv virtualenv 3.6.0 jupyter-notebooks

&lt;span class="c"&gt;# Start the virtual environment&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;pyenv activate jupyter-notebooks 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next, install all of the dependencies you'll require:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pip install jupyter pandas numpy matplotlib seaborn
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Finally, start your jupyter server in the directory you would like to save your notebooks:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ jupyter notebook
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--r8uwn2TZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/xmsgvlp5k8ey0bjj0ncm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--r8uwn2TZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/xmsgvlp5k8ey0bjj0ncm.png" alt="The Empty Jupyter Interface"&gt;&lt;/a&gt;&lt;/p&gt;

A New Jupyter Window

&lt;h2&gt;
  
  
  Creating a notebook
&lt;/h2&gt;

&lt;p&gt;Notebooks are created using the dropdown in the top right hand corner of the page. Jupyter will automatically open and start the notebook so you'll be ready to go.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--t_eRqFZb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/toxaas293t172mb9aizs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--t_eRqFZb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/toxaas293t172mb9aizs.png" alt="Jupyter new notebook dropdown"&gt;&lt;/a&gt;&lt;/p&gt;

The Jupyter New Notebook Dropdown Menu

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MZ9Mvd-Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/jvh0rn7qf27vfye95j11.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MZ9Mvd-Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/jvh0rn7qf27vfye95j11.png" alt="Empty Jupyter notebook"&gt;&lt;/a&gt;&lt;/p&gt;

An Empty Jupyter Notebook

&lt;p&gt;Like with any other Python file, it is best practise to include your imports at the top of the file. In Jupyter, we can use the first cell for these. Shift + Enter runs the cell once you've written your script.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Pandas for manipulating dataframes
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;pandas&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;

&lt;span class="c1"&gt;# Matplotlib for inline graphs and plots
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;matplotlib&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pyplot&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;plt&lt;/span&gt;
&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;matplotlib&lt;/span&gt; &lt;span class="n"&gt;inline&lt;/span&gt;

&lt;span class="c1"&gt;# Seaborn for plot styles.
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;seaborn&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;sns&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Reading in data
&lt;/h2&gt;

&lt;h3&gt;
  
  
  CSV
&lt;/h3&gt;

&lt;p&gt;Pandas has a handy function for reading in csv files. Below are a couple of examples, but Chris Albon has a &lt;a href="https://chrisalbon.com/python/data_wrangling/pandas_dataframe_importing_csv/"&gt;great blog post&lt;/a&gt; about importing csv files if you need more information.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# if the file has headers
&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;read_csv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'path_to_file'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# if the file has no headers
&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;read_csv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'path_to_file'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Exploring data
&lt;/h2&gt;

&lt;p&gt;There are a number of methods to explore a data-frame once it has been loaded. To inspect the first &lt;em&gt;n&lt;/em&gt; rows, use the &lt;code&gt;head&lt;/code&gt; function which returns the first 5 rows by default but can return any given number.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Print the first 5
&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;# Print the first 10
&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;To find out some basic information about the data held within the data-frame, the &lt;code&gt;describe&lt;/code&gt; function outputs a summary of the values excluding any &lt;code&gt;NaN&lt;/code&gt; values.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Finally, to view a data-frame in its entirety pandas provides an &lt;code&gt;option_context&lt;/code&gt; function to temporarily set options within a &lt;code&gt;with&lt;/code&gt; context.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Set the max rows to print to 999 and print.
&lt;/span&gt;&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;option_context&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'display.max_rows'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;999&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Modifying and filtering data
&lt;/h2&gt;

&lt;p&gt;To access individual columns and values in a data-frame, pandas provides the &lt;code&gt;loc&lt;/code&gt; parameter.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# fetch a column
&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'column_name'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;# fetch a row
&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loc&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'index_value'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;# fetch a single value
&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loc&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'index_value'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'column_name'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;# filter a data-frame by a given condition
&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loc&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'column_name'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Columns can be added or modified easily using the &lt;code&gt;apply&lt;/code&gt; function&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# create a new column based on other column values
&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'new_column'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'old_column'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# override a column
&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'old_column'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'old_column'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Basic graphs
&lt;/h2&gt;

&lt;p&gt;Graphing in Jupyter notebooks is as easy as calling a single seaboard function.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# create a line plot using your data frame
&lt;/span&gt;&lt;span class="n"&gt;sns&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lineplot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"my_x_field"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"my_y_field"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;my_data_frame&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bFrpSCYD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/rah0c6p0jcw8hbel1lb4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bFrpSCYD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/rah0c6p0jcw8hbel1lb4.png" alt="A line plot"&gt;&lt;/a&gt;&lt;/p&gt;

An Example Line Plot



&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# create a scatter plot
&lt;/span&gt;&lt;span class="n"&gt;sns&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;scatterplot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"my_x_field"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"my_y_field"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"attribute_z"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;sizes&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="c1"&gt;# size boundaries
&lt;/span&gt;                &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;my_data_frame&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--48kc_yto--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/xbcicclke90cjtdqu0wh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--48kc_yto--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/xbcicclke90cjtdqu0wh.png" alt="An example scatter plot"&gt;&lt;/a&gt;&lt;/p&gt;

An Example Scatter Plot

&lt;p&gt;The &lt;a href="https://seaborn.pydata.org/examples/index.html"&gt;Seaborn website&lt;/a&gt; provides a comprehensive list of examples, each with the code snippet used to generate them and some example data sets to explore.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus
&lt;/h2&gt;

&lt;p&gt;Recently, GitHub has started rendering Jupyter notebooks in their UI, making it easier than ever to run and share notebooks. The iPython repository has a &lt;a href="https://github.com/ipython/ipython/blob/6.x/examples/IPython%20Kernel/Index.ipynb"&gt;good example&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Useful links
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://pandas.pydata.org/"&gt;Pandas&lt;/a&gt;&lt;br&gt;
&lt;a href="https://seaborn.pydata.org"&gt;Seaborn&lt;/a&gt;&lt;br&gt;
&lt;a href="https://jupyter.org/"&gt;Jupyter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>jupyter</category>
      <category>datascience</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
