Posts

Showing posts from April, 2021

Golang vs Python: 6 Questions to Decide Which Programming Language is Best For You

Image
The post Golang vs Python: 6 Questions to Decide Which Programming Language is Best For You first appeared on Qvault . These two coding languages duke it out – but who’s the winner? Question Tentative Winner Brief historic description of Golang vs Python – Golang vs Python: Which coding language is best for beginners? Python Golang vs Python: Which coding language is best for experienced coders? Go Golang vs Python: Which language is best for a job in computer science?  Go/Python Golang vs Python: Which language is best for machine learning? Python (but only for now) Golang versus Python: Which language is best for programmer productivity?   Go Golang vs Python: Which language is best for the future?  Go So what’s the final answer in Golang vs Python? Depends on where you’re going! In a world where the ability to write any code at all is a tremendous advantage, often the biggest problem coders face is knowing which language...

The Ultimate Guide to JSON in Go

Image
The post The Ultimate Guide to JSON in Go first appeared on Qvault . Being a language built for the web, Go offers feature-rich support for working with JSON data. JSON (JavaScript Object Notation) is an unbelievably popular data interchange format whose syntax resembles simple JavaScript objects. It’s one of the most common ways for web applications to communicate. Encoding and decoding with struct tags Go takes a unique approach for working with JSON data. The best way to think about JSON data in Go is as an encoded struct . When you encode and decode a struct to JSON, the key of the JSON object will be the name of the struct field unless you give the field an explicit JSON tag . type User struct { FirstName string `json:"first_name"` // key will be "first_name" BirthYear int `json:"birth_year"` // key will be "birth_year" Email string // key will be "Email" } Example marshal JSON from struct (encode) The enco...

Migrating From Vue-CLI & Webpack to Vitejs

Image
The post Migrating From Vue-CLI & Webpack to Vitejs first appeared on Qvault . Qvault’s web app that hosts all of my coding courses is a single-page application written in Vue 2, with plans to migrate to Vue 3 soon™©® . In the meantime, I happened across a cool new tooling app called Vite that promised a few things that caught my attention. Nearly instant development server startup time Hot module replacement out of the box Simple configuration Out-of-the-box support for ES modules This particularly resonated with me because my (fairly) simple app’s development server took over 10 seconds to start up with the Vue-cli and Webpack , and I’ve spent many hours in the past trying to configure Webpack and Babel , when I just needed basic Vue configurations. Let’s look at some quick anecdotal comparisons before I dive into the migration guide, so you can see if the benefits of switching are worth it for you. Vite Vue-cli + Webpack Dev server start time ~600ms ~1...

Search and Replace Strings in Golang – Top 5 Examples

Image
The post Search and Replace Strings in Golang – Top 5 Examples first appeared on Qvault . Go has a powerful standard library that makes string manipulation easy right out of the box. One of the functions I use most often is the strings package’s Replace() function. strings.Replace() returns a copy of its input string after searching and replacing all instances of the given substring with a new one. strings.Replace() signature func Replace(s, old, new string, n int) string Notes s is the original string that contains parts that need to be changed. old is the substring you want to be replaced. new is the substring that will be swapped out for old . n limits the number of replacements. If you want to replace them all, just set n to -1 , or use the more explicit ReplaceAll function. Example #1 – Replacing delimiters Let’s say you have some comma-separated-values, CSVs. Perhaps you want to separate each word with a space instead of a comma . This can be useful if y...

How and Why to Write Enums in Go

Image
The post How and Why to Write Enums in Go first appeared on Qvault . An  enum , which is short for  enumerator , is a set of named constant values. Enums are a powerful tool that allow developers to create complex sets of constants that have useful names yet simple and unique values. Syntax Example Within a constant declaration, the  iota  keyword denotes successive untyped integer constants. type BodyPart int const ( Head BodyPart = iota // Head = 0 Shoulder // Shoulder = 1 Knee // Knee = 2 Toe // Toe = 3 ) Why should you use enums? Why would you want an integer constant called Head with a value of 0 ? And if you did, couldn’t you just use const Head = 0 ? Yes, you could do that, but enums are powerful by how they group sets of constants and guarantee unique values. By using an enum, you’re ensured by the compiler that none of the constants in your group ( Head , Shoulder , Knee , and Toe...

Splitting a String into a Slice in Golang

Image
The post Splitting a String into a Slice in Golang first appeared on Qvault . I can’t begin to tell you how often I split strings in Go. More often than not I’m just parsing a comma-separated list from an environment variable, and Go’s standard library gives us some great tools for that kind of manipulation. Split by commas or other delimiters strings.Split strings.SplitN Split by delimiters and retain the delimiters strings.SplitAfter strings.SplitAfterN Split by whitespace and newlines Split using a regex Split by commas or other delimiters strings.Split() Go’s rich standard library makes it really easy to split a string. 99% of the time you need to split strings in Go, you’ll want the strings package’s strings.Split() function . package main import ( "fmt" "strings" ) func main() { fruitsString := "apple,banana,orange,pear" fruits := strings.Split(fruitsString, ",") fmt.Println(fruits) // p...

Backend Developers are UX Designers Too

Image
The post Backend Developers are UX Designers Too first appeared on Qvault . Too often I neglect the idea of UX design in backend work. The goal of user experience design is to give users a product that’s easy to use. In the world of front-end development, that typically means making it obvious how to navigate your site, using commonly-understood icons, or implementing well-contrasted colors for foreground and background, making your site easy to read. I’m here to contend that UX is extremely important in backend development as well, the difference is simply that our users are typically other developers, sometimes even internal employees, rather than users of the final product. What is UX (user experience) design? User experience design (UXD, UED, or XD) is the process of supporting user behavior through usability, usefulness, and desirability provided in the interaction with a product. User experience design encompasses traditional human-co...

All the Ways to Write for Loops in Go

Image
The post All the Ways to Write for Loops in Go first appeared on Qvault . A for loop executes a block of code repeatedly, and in Golang, there are several different ways to write one. The standard three-component loop For-range loop Range over slice Range over map Range over channel Range over string While loop Optional components loop Infinite loop Break from a loop Continue (skip to the next iteration) in a loop #1 The standard three-component loop Go has fairly standard syntax for the three-component loop you’re probably used to from C, Java, or JavaScript. The big difference is the lack of parentheses surrounding the components. for i := 0; i < 100; i++ { sum += i } The three components are the init statement, i := 0 , the condition, i < 100 , and the post statement, i++ . The steps of executing the loop are as follows. The init statement executes and variables declared there are made available to the scope of the loop’s body. The condition is co...

Advanced Algorithms Course Released on Qvault

Image
The post Advanced Algorithms Course Released on Qvault first appeared on Qvault . Sorry it took so long for me to get this one out! Advanced Algorithms was just released, and I’m excited to let you all get your hands on it, even if you’re just auditing it for free! The more advanced material takes quite a bit longer to produce, I wanted to triple check to make sure I got everything correct and that I’ve presented it in a way that makes it easy to understand. The course, like it’s prerequisite Bit-O Data Structures , is written in Python, so most of the algorithms you write will be Python classes. Aside from the Python coding exercises that you can complete in your browser, there’s also multiple choice questions that help ensure you’ve digested the reading material. Sometimes the more math intensive stuff simply can’t be learned easily through code, so you’ve got to do a bit of reading. While it’s not completely necessary to take my Big-O Data Structures and Big-O Algorithms cou...

Naming Variables the Right Way

Image
The post Naming Variables the Right Way first appeared on Qvault . I’ve noticed that more and more often that bugs introduced into an existing codebase are due to the poor naming of variables way more often than I think you would expect. Someone uses a rateLimit variable expecting it to be denominated in seconds but instead, it’s in minutes , resulting in a wildly different polling schedule. Another developer expects dbConnection to be an open database connection, but instead, it’s just the connection URI. Using descriptive, concise, and conventional variable names can really set apart a senior from a junior developer. Here are some of my rules of thumb for high-quality variable nomenclature. Following existing naming conventions of the language or framework that you’re using Single letter variables have a place, and that place is rare Include units in your variable names Include types in your variables names if it isn’t obvious Make the name as long as necessary but no lon...