Cowboy Coding to Professional Developer

What I would have told myself when I was a hobbyist

Daniel Hitchcock
Analytics Vidhya
9 min readFeb 27, 2020

--

It was only 8 months ago that I was hacking together scripts in my spare time. I didn’t know any of the formal programming etiquette, but I was my own person and got things done.

I called this Cowboy coding.

Once I got a job as a professional developer, I learned what I was missing out on. These are the things I would I could have told myself, as well as the advice I give to anyone who is dabbling in software development.

1. Use a Real IDE

If you are a Python user and are still using IDLE, immediately download VSCode. Or PyCharm. Or Atom. They are free, and offer a myriad of features to help you. If you program in another language, do a little research to find out what the best IDE is. I currently use PyCharm for Python (and Jupyter Notebook), and VSCode for JavaScript, HTML, TypeScript, Go, and pretty much anything else.

Using such a developed, high tech tool might feel like overkill for your 10 line hello-world test scripts, but the moment you begin to develop multi-file projects, or need to jump around between them, or experiment with different environments, you’ll understand why a sophisticated IDE is so important.

  1. Support For Multi-File Projects — Before you know it, your projects will no longer be simple single file apps. It’s great to manage them together instead of clicking through windows.
  2. Support For Multiple Languages — You will learn other programming languages, there’s no way of getting around it. And as your projects become more complex, you’ll suddenly find they’re made of more than one language. In VSCode, I can easily hop between Python, Go, and Javascript.
  3. Plug-Ins — There are huge communities behind these IDEs, developing open source plugins, trying to make all of our lives easier. There are plugins for Code Formatting (see below), Git integration, testing, viewing MarkDown files or HTML; if there is something you need, someone has probably created a plugin for it.
  4. Introspection — I can highlight a function in my program and it will tell me its arguments. I can hit ‘tab’, and my IDE will autocomplete what I was typing, or at least give great suggestions. I can also click on a term, and it will take me to where that variable/function was declared, or perhaps show me everywhere it is used.

2. Use a Code Formatter (and Linter)

I cannot stress this enough. **Use a Code Formatter!** This is not cheating! Using a code formatter does not make you less of a programmer; it makes you a smart person who wants to get stuff down and look good in the process. Less time spent formatting means more time for programming.

If you are using Python, I highly recommend Black. It can be added to any real IDE. It can even be invoked every time you save file. For Javascript/Typescript, there is Prettier. For Go, well, Go has its own built in gofmt.

So satisfying.

Similarly, you need to install a linter. A linter lets you know if you have variables mistyped, or unused imports, any any other common coding errors. PyCharm comes installed with one, but I would recommend adding Pylint.

“Unnecessary use of a comprehension”? — I’ll be the judge of that.

3. Control Your Environment

Let’s again say you’re a Python developer. What version of Python are you using? If you are like I was, your response is probably “Um, 3-point… something. What’s it matter?” The correct response should be “For which project?”

Version Conflicts in Your Projects

Let’s say you had a really cool project called Old_Project. You start working on New_Project, and quickly find out that a new feature you need isn’t available with your version of Python or some library. So you upgrade, and what happens?

Old_Project no longer works.

And why should it? It never agreed to work with all this new fangled software you just upgraded to. So what’s the solution?

Have your own environments for New_Project or Old_Project. Heck, have a different environment for each project if you like!

Step 1: Get An Environment Manager (Conda for Python)

Conda makes this incredibly easy in Python, and other languages have similar tools. If you don’t have Conda, download Anaconda or Miniconda and use it as your default Python distribution.

For creating a new environment, simply type conda create -n cool-environment , then conda activate cool-environment, and you’re there. When your done, conda deactivate. You can also set this environment in PyCharm project settings if that’s your thing.

Step 2: Use a Makefile

Wanna’ really step up your game? Create a file in every one of your projects entitled environment.ymland invoke it with a Makefile. environment.yml holds your environment information, and Makefile has the means to run this script. This offers incredibly tight control of your environment and prepares your project to be run on various systems.

Two little files, and worry free environment support! Look at those cool icons.

Here’s an environment.yml example:

name: old_project
channels:
— defaults
dependencies:
— python=3.6
— pandas=0.25

This could be invoked by typing conda env create -f environment.yml. But Makefiles are the way to go. Here’s a very basic example:

setup: env-setupremove: env-removeenv-setup:
conda env create -f environment.yml
env-remove:
conda env remove -n old_project

When you type make setup, this builds a conda environment under tight version control. If you need to remove it, simply type make remove. Each project can have its own environment.yml and Makefile!

Here’s an action shot in Pycharm. (Note: how each file has its own syntax highlighted — i.e. Use a real IDE!)

Anyone who downloads your project can instantly create a compatible environment!

4. Drop Dropbox; Get Git

Dropbox is not version control

Yes, I happily used Dropbox to keep my files safe and synced for 4 years. There were a few minor inconveniences, like resetting my environment every time I went from Desktop to Laptop, or dealing with conflicted copies, but it worked..

But would you know? — There is a program developed to address this specific issue!

Git, when used with a remote repository, accomplishes everything you’re using Dropbox for right now. And substantially more.

Keep Your Project Safe With GitHub

GitHub is so kind as to host Git projects for free! You can have an unlimited number of public repos and 3 private ones. If you’re using Git, you simply need to push your changes to the remote repo. You don’t even need to use “complicated” git commands: just commit your changes and push. When you switch workstations, a quick “git pull” and now you can begin right where you left off.

If you ever apply for software development jobs, your GitHub repo is a perfect way to advertise yourself. Hiring managers will definitely be looking at this, and you should be proud to show it . Put it on your resume, show your enthusiasm!

Back to Git — It’s not just a glorified file sharing platform…

A Case Study With Branches — Add a New Feature

Take, for example, a situation where you need to add a Cool New Feature to your program. Only problem is this will take a week to implement, and you need your program function tomorrow.

In the DropBox world, you would have to copy and paste your entire directory tree and start hacking… now you have two directories taking up space, and to merge your changes in, you need to do some awkward copy-paste acrobatics. This is obviously an anti-pattern.

In the Git world, you can make branches of your code and effortlessly hop between them. You could type git checkout -b cool_new_feature. This will create a new branch of your code called “cool_new_feature”, a whole virtual playground to experiment with your program. IDEs are all prepared for this, and they happily update your code when a new branch is invoked. If you need to revert to your functioning program, commit your changes and simply type git checkout master. Boom — functioning code! Once you’re ready to start working on your feature, type git checkout cool_new_feature and pick up right where you left off. Once you’re finished, merge into master by typing git checkout master, git merge cool_new_feature.

Simplified Git Workflows

If this sounds complicated, there are workflows on how/when to branch and conventions for naming. My group uses Git Flow. But this is overkill for small projects, and I would recommend GitHub Flow for the hobbyist. If you’re the only person working on a project, 95% of your Git commands will be git commit, git branch <new branch> , git checkout <branch>, git push, git pull , git merge <branch>.

Software Development Process

Also, take this as an opportunity to learn about software development in general. Each branch should only accomplish one goal, be it a new feature, a bugfix, or some other chore.

I promise you: You will not regret learning Git!

6. Don’t Think You’re Not Good Enough

I used to have this mindset that anything I wrote, someone else could do it way better. This even used to prevent my from writing tools which turned out to be quite successful, thinking it would be a disservice to push my inferior product!

Don’t Sweat the Complicated Stuff

Do you know the difference between a Class attribute and an Instance attribute? “Python Path” vs “System Path”? Do you know how to cythonize a async decorated generator in a recursive function?

A lot of developers would answer “No” to these questions too. And that’s fine.

It’s great to be mindful of program features, but if you don’t need to use them, don’t worry about it. It doesn’t make you an inferior programmer because you use a Dictionary where everyone else tries to create a Class (some might argue it would make you a better programmer).

If you’re writing programs that solve your needs, that means you are good enough. That doesn’t mean there isn’t a better way to do it, of course, which brings me to my next point:

Find a Friend

The biggest difference between me now and 8 months ago is that I’m surrounded by 7 other professional developers. We all have strengths and weaknesses and some of us are more experienced, but none of us know everything that the remaining six combined do.

I have seven people I can go to for questions. Seven people who can review my work. Seven people creating code masterpieces that I can read, and think “Oh, interesting..” (and not always sarcastically). I’m no longer stuck spinning my wheels on trivial issues that someone else can easily solve. I can ask them.

It’s way better than being shamed on Stack Overflow.

Find some friends and get involved. Are there two of you developing the same/similar projects? Start an Agile group! Even if neither of you are particularly experienced, there is a lot of learning that can happen.

In Conclusion…

Programming is NOT Only About Writing Code

How much actual code did I show in this article? Almost none.

I used to think to be a better programmer, I would need to learn the nitty-gritty of Python. But most of my growth as a developer hasn’t been about gaining an expert knowledge of Python, but about everything surrounding it. Things like learning REST, AWS, or just how to structure a multi-piece projects.

I also didn’t think I stood a chance when I was applying to software development jobs, but here I am. If you are passionate about coding, there is a place for you.

Some Other Things

The suggestions I listed above are universal for any programming language, and it is worth your effort to study them in depth. It won’t be wasted time.

Some other small suggestions:

  • Make Unittests. I recommend PyTest, and bonus points for invoking it with your Makefile (make test).
  • Get comfortable with the command line!
  • Learn another programming language! Is you favorite dynamically typed? Learn a static typed language (like Go!). It will change how you think about programming, and ultimately make you better.
  • Learn basic web stuff and REST. Learn how to make a simple website and a REST back-end. A little goes a long way.

Some Useful Links

Image credits:

Cowboy hat: https://www.1001freedownloads.com/free-clipart/cowboy-hat-2

Tie: https://www.1001freedownloads.com/free-clipart/necktie

Gifs created with: https://www.screentogif.com/

--

--

Daniel Hitchcock
Analytics Vidhya

I am a former Biochemist and current Python developer. I also dabble in Angular, Go, and AWS serverless apps. Most of my work involves Data.