Don’t be such a square!

Image for post
Image for post
Photo by Paul Einerhand on Unsplash

Reading back over traits in “The Book” of Rust (that has a biblical feel, doesn’t it?), I realized something that was totally impossible in Go: implementing traits for non-local types i.e. types that you did not create yourself. To see what I mean concretely, let’s say that we wanted to define a square method for floating-point numbers. Sure, it’s actually far fewer keystrokes to just multiply the value by itself, but let’s say we wanna be extra explicit (as things are often better that way). …


With tests! And plenty of apples.

Image for post
Image for post
Photo by Priscilla Du Preez on Unsplash

I have been scratching my head lately trying to think of something to do with Go. It’s a perfectly simple, easy-to-use language with a lot of boxes ticked and yet I have been unable to think of anything. Finally, the inspiration struck me: a thread-safe cache with tests. Now, since Go is a relatively high-level language, the actual implementation of this (extremely simple) cache is only wrapper functions around the map data structure. However, it is a good project to get familiar with writing tests and some good Go-isms.

Let’s start my getting our project structure ready. For me, this…


result, result_str, result_str_str…

Image for post
Image for post
Photo by Martino Pietropoli on Unsplash

I’ve been programming in Go again recently after a little hiatus and it has unfortunately brought to my attention the language’s lack of variable shadowing.

Variable shadowing is when you can redefine a variable in your scope and it allows you to do things such as:


Image for post
Image for post

Hey hackers! Welcome to HOTH IV, ACM Hack’s 12-hour hackathon that welcomes you whether this is your first or sixth hackathon!

This article is meant to be a sort of reference guide for things that might be useful for people of all experiences in all the very different areas of development.

Git

Anytime you’re coding with other people (and even when you’re not), it can be really important you have a record or archive of all the different code versions that you’ve made. This makes it easy to review, merge, and revert back to code that you want.

The overwhelmingly popular…

Dustin Newman

Go, Rust, and C++. If you say it aloud, it almost rhymes.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store