5 Ways to Learn & Improve Your Programming Language Use

Posed the question,

What to write when starting to learn and programming language?

I started an answer to the question in this video. But read on for more extensive list and details!

I’ve written up this article. It started last week when I wrote up “Top 5 Ways to get the coding basics down!” This week I wanted to delve deeper into a specific item on that list and provide what I came up with, which is this List of 10 things to write in order to effectively learn a programming language.

1. Find a Known Domain

What I mean by this is to find a domain that you personally know. It seemed the 80’s generation of programmer dorks wrote role playing game character generators for Dungeons & Dragons. I did myself but for Robotech. But there’s a million other domains that you would know, and those domains are what you should pick and find data and actions in that domain you could implement with code.

Two examples I’ve used recently includes the made up e-commerce store of Better Botz, a store that works with the domain of robots and mecha, and Railroads such as Union Pacific, Norfolk Southern, Amtrak, and the respective domain around that. Many of the other things you could use might be transportation, automotive, health care, or more specific the universe of Harry Potter, Star Wars, Tumble Leaf, Sesame Street, style and fashion trends,

2. Model a Domain According to the Language

Let’s say you’re learning JavaScript. Whatever the domain you’ll want to find actions and data to implement and use specificly to how the language is best used. With JavaScript that would be to use the language features and design to build a working application, like; perform mathematical calculations, such as with bigint, using dynamic import, chaining, promises, async and await, global variables, arrow functions, inheritence through prototyping, and how the properties and methods, or functions, for starters work best for the application domain.

In C#, Java, Rust, Go, Erlang, F#, and other languages these features and characteristics would be different. Whatever the language, make a list of the features and characteristics that are widely used and work with those to best implement the application domain.

List Interupt: Refactoring

I’ve written this list in order of what I personally have found the easiest path in gaining a high level of profiecience with a programming language. You could however mix the list to your preferred style. However at this point between the first two item efforts and the next a new skill will be learned both out of necessity and intent: refactoring.

Code Refactoring is the process of restructuring existing computer code—changing the factoring—without changing its external behavior. Refactoring is intended to improve the design, structure, and/or implementation of the software (its non-functional attributes), while preserving the functionality of the software. Potential advantages of refactoring may include improved code readability and reduced complexity; these can improve source code maintainability and create a simpler, cleaner, or more expressive internal architecture or object model to improve extensibility.”

3. Learn to Test

Learning to test an application will help you tremendously in writing better code. If you’ve committed the actions of the first two items in this list, this is an opportunity to significantly refactor the application you’ve built around your known domain. You’ll need to break apart existing functions so that they’re bit size enough to test. Sometimes you’ll need to differentiate between making some testable at a small unit size versus across an application’s hard boundaries, like an integration test between a database and the application’s data access code.

Pushing for testing the core domain functionality of the application is the best thing to focus on. Don’t worry about the specifics of testing if data is written to the database, or data is retrieved from the database, as much as testing that a function returns the specific answer you expected based on passing it the specific parameters you’ve assumed it would be given. This isn’t to say sometimes you may want to test what you’ve written to the database, so sure, that is something that you can test. But focusing on the core application domain functionality will ensure the best return on your investment of time!

4. Clean Coding Practices

Once you’ve gained familiarity with the language by building an application or two using the features, rooted in a known domain that you understand well, and have some test coverage of the application, refactor that application using clean coding practices. Clean code is often described using the SOLID principles:

  • Single Responsibility Principle
  • Open / Closed Principle
  • Liskov Substitution Principle
  • Interface Segregation Principle
  • Dependency Inversion Principle

See also: KISS (Keep It Simple Stupid), DRY (Don’t Repeat Yourself), YAGNI (You Aint Gonna Need It), and others.

The idea behind these, is to keep the application code regardless of languages as simple as it can possibly be. With a secondary effect that once software becomes painful to modify, it should be changed as to make modification simpler. Thus the idea of refactoring to the SOLID principles listed, and doing so continuously will keep software in a usable, maintainable, and one could arguable say even a performant state.

5. The Hardest Suggestion: Naming & Thinking

It is often stated, “The hardest problem in computer science is naming things.” to which I, not in jest, whole heartedly agree. Elements in programming, programming design, programming implementation, and every permeable space around programming is littered with poorly named things. I don’t blame anybody because it is damned hard to get a good name for features and functionality, and have truth in the naming of those features and functionality remain throughout the course of its lifetime.

Naming is hard, which I’d combine to say stop programming regularly and think about your naming. Think about refactoring to names that are more accurate to the intent. Stop and ponder what a good name would be, and if the function or feature will replication what that name implies. Add in some metaphysical thought to the whole effort, talk it through with someone you know (or a stranger, it’s a good skill for debuggin!), but think, think, ponder, analyze, and think some more.

The short of the long part of this suggetion can simply be summarized as: Practice naming things, think a bunch, then rename things, and repeat this cycle.

In Summary

To really get a programming language down by heart, be able to readily implement pretty much anything, this is my go to list of actions and practices to follow. Hopefully, it’ll provide you with some ideas to explore how best you would also like to go about learning a programming language. I’m always open to suggestions, comments, thoughts, and discussions on the topic, so feel free to ping me via the Twitters @Adron.

Search Words

Type in any of the following, in pretty much any search engine, like duckduckgo to dig up the latest and greatest on this topic.

  • Single Responsibility Principle
  • Open / Closed Principle
  • Liskov Substitution Principle
  • Interface Segregation Principle
  • Dependency Inversion Principle
  • How to Model a Domain
  • Clean Coding Practices
  • Unit Testing
  • Unit Testing Practices
  • SOLID Principles
  • Package Principles (REP, CRP, CCP, ADP, SDP, SAP)
  • Don’t Repeat Yourself (DRY)
  • Keep It Simple Stupid (KISS)
  • You Aint Gonna Need It (YAGNI)

Finally Solidified, Twitch Scheduling

twitch-logo-sizedIt’s been a year plus now that I’ve been streaming on Twitch (FOLLOW on the channel, it’s free not a paid subscription or anything). At points it has been weekly, sometimes every other week, sometimes every day of the week, or in some cases even more intermittently or frequently. The schedule, considering, has been kind of ridiculous. But that has now changed.

Continue reading “Finally Solidified, Twitch Scheduling”

A Really Quick Introduction to Minikube

There’s likely a million introductions to Minikube, but I wanted one of my own. Thus, here you go!  Minikube is basically Kubernetes light that runs on your own machine. Albeit, it does this similarly to how Docker used to do it, via a virtual machine. Thus, you can do some things with it but if you want to get serious you’ll still need to spool up a proper cluster somewhere as it will start to bog down your machine with any heavy workloads.

1: Minikube – Installing

Linux Direct:

 curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \
   && sudo install minikube-linux-amd64 /usr/local/bin/minikube

Linux Debian:

 curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \
   && sudo install minikube-linux-amd64 /usr/local/bin/minikube

Linux Red Hat:

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-1.4.0.rpm \
 && sudo rpm -ivh minikube-1.4.0.rpm

2: Starting Minikube

minikube start will start a minikube instance, pulling images, resources, kubelets, kubeadm, dashboard, and all those resources.

00-starting

3: Stopping Minikube

minikube stop brings the minikube service to a stop, allowing for restart later.

09-stopping-minikube

4. Deleting Minikube

minikube delete will delete the minikube. This will delete any of the content or related collateral that was running in the minikube.

01-delete

5. Restarting after Delete

minikube start this is the way to restart a minikube instance after you’ve stopped the instance. It’s also the way start a minikube, as shown above.

03-restarting-after-delete

6. Starting a Named Minikube

If you want a named minikube instance, use the -p switch, with a command like minikube start -p adrons-minikube.

04-minikube-with-name

7. Starting & Using the Dashboard

To check out the dashboard, that pretty Google dashboard for Kubernetes, run minikube dashboard to bring that up.

05-starting-dashboard

06-minikube-dashboard.png

8. Status!

To get a quick update on the current state of the minikube instance just run minikube status.

07-other-minikube-commands

9. Starting Minikube sans a Virtual Machine

This is, albeit I may be mistaken, this is a Linux only feature. Run minikube start --vm-driver=none and it’ll kick off a minikube right there on your local machine.

09-minikube-no-vm-started.png

References:

Learning Go Episode 4 – Composite Types, Slices, Arrays, Etc.

Episode Post & Video Links:  1, 2, 3, 4 (this post), 5, 6, 7, and 8. Non-linked are in the works! Videos available now on Youtube however, so check em’ out!

If you’d like to go through this material too in book form, I highly suggest “The Go Programming Language” by Alan A.A. Donovan & Brian W. Kernighan. I use it throughout these sessions to provide a guideline. I however add a bunch of other material about IDE’s, development tips n’ tricks and other material.

8:00 Starting the core content with some notes. Composite types, arrays, slices, etc.
11:40 Announcement of my first reload – http://compositecode.blog/2019/02/11/… – second successful time blogged here) of the XPS 15 I have, which – https://youtu.be/f0z1chi4v1Q – actually ended in catastrophe the first time!
14:08 Starting the project for this session.
16:48 Setting up arrays, the things that could be confusing, and setup of our first code for the day. I work through assignment, creation, new vs. comparison, and various other characteristics of working with arrays during this time.

fmt.Println("Hello, let's talk composite types.")
basketOfStuff := [3]string{"The first string","second","This string."}
var zeeValues [2]int
for i, v := range basketOfStuff {
fmt.Printf("Value %d: %s\n", i, v)
}
fmt.Println(zeeValues)
if zeeValues[0] == zeeValues[1] {
fmt.Println("The values are the same, this doesn't instantiate like the `new` keyword.")
} else {
fmt.Println("The way go appears to instantiate unset variable values, such as in this array is like the `new` keyword instantiation.")
}
zeeValues[0] = 1 + 52 * 3
zeeValues[1] = 9
fmt.Println(zeeValues[len(zeeValues) 1])

29:36 Creation of a type, called Currency, of type int, setting up constants, and using this kind of like an enumerator to work with code that reads cleaner. Plus of course, all the various things that you might want to, or need for a setup of types, ints, and related composite types like this.

type Currency int
const (
USD Currency = iota
CAN
EUR
GBP
JPY
NOK
SEK
DKK
)
symbol := []string{USD: "$", CAN: "$", EUR: "€", GBP: "£", JPY:"¥", NOK:"kr", SEK:"kr",DKK:"kr"}
fmt.Println(EUR, symbol[EUR])
fmt.Println(JPY, symbol[JPY])
r := []int{99: 1}
r[36] = 425
r[42] = 42
fmt.Println(r[36] + r[42])
fmt.Println(strconv.Itoa(r[36]))

view raw
currency.go
hosted with ❤ by GitHub

43:48 Creating an example directly from the aforementioned book enumerating the months of the year. This is a great example I just had to work through it a bit for an example.

months := []string{1: "January", 2:"February", 3: "March", 4:"April", 12:"December"}
for _, s := range months {
fmt.Printf("The month: %s\n", s)
}
var runes []rune
for _, r := range "Language: 走" {
runes = append(runes, r)
}
fmt.Printf("%q \n", runes)
var x, y []int
for i := 0; i < 10; i++ {
y = appendInt(x, i)
fmt.Printf("%d cap=%d\t%v\n", i, cap(y), y)
x = y
}

view raw
the_months.go
hosted with ❤ by GitHub

52:40 Here I start showing, and in the process, doing some learning of my own about runes. I wasn’t really familiar with them before digging in just now!

the rest of the main.go file is here…
var runes []rune
for _, r := range "Language: 走" {
runes = append(runes, r)
}
fmt.Printf("%q \n", runes)
var x, y []int
for i := 0; i < 10; i++ {
y = appendInt(x, i)
fmt.Printf("%d cap=%d\t%v\n", i, cap(y), y)
x = y
}
}
func appendInt(x []int, i int) []int {
var z []int
zlen := len(x) + 1
if zlen <= cap(x) {
z = x[:zlen]
} else {
zcap := zlen
if zcap < 2* len(x) {
zcap = 2 * len(x)
}
z = make([]int, zlen, zcap)
copy(z, x)
}
return z
}

view raw
main.go
hosted with ❤ by GitHub

1:09:40 Here I break things down and start a new branch for some additional examples. I also derail off into some other things about meetups and such for a short bit. Skip to the next code bits at the next time point.
1:23:58 From here on to the remainder of the video I work through a few examples of how to setup maps, how make works, and related coding around how to retrieve, set, and otherwise manipulate the maps one you’ve got them.

package main
import "fmt"
func main() {
ages := map[string]int{
"Peterson": 52,
"Sally": 22,
"Javovia": 15,
"Ben": 42,
}
jobAssociation := make(map[string]string)
jobAssociation["Peterson"] = "Engineer"
jobAssociation["Sally"] = "CEO"
jobAssociation["Jovovia"] = "Gamer"
jobAssociation["Ben"] = "Programmer"
printAges(ages)
printJobAssociations(jobAssociation)
fmt.Println(ages)
fmt.Println(jobAssociation)
fmt.Println(jobAssociation["Jovovia"])
fmt.Println(jobAssociation["Frank"]) // Blank! 😮
fmt.Println(ages["Sally"])
delete(ages, "Sally")
fmt.Println(ages)
fmt.Println(ages["Sally"])
delete(jobAssociation, "Jovovia")
fmt.Println(jobAssociation)
fmt.Println(jobAssociation["Jovovia"]) // Blank.
ages2 := map[string]int{
"Frank": 52,
"Johnson": 22,
"Smith": 15,
"Jezebelle": 42,
}
ages3 := map[string]int{
"Frank": 52,
"Johnson": 22,
"Smith": 15,
"Jezebelle": 42,
}
if equal(ages, ages2) {
fmt.Println("Naw, not really equal.")
} else {
fmt.Println("This is correct, not equal.")
}
if equal(ages2, ages3) {
fmt.Println("True, these are effectively the same map values and keys.")
}
}
func printJobAssociations(associations map[string]string) {
for name, job := range associations {
fmt.Printf("%s\t%s\n", name, job)
}
}
func printAges(ages map[string]int) {
for name, age := range ages {
fmt.Printf("%s\t%d\n", name, age)
}
}
func equal(x, y map[string]int) bool {
if len(x) != len(y) {
return false
}
for k, xv := range x {
if yv, ok := y[k]; !ok || yv != xv {
return false
}
}
return true
}

view raw
map_types.go
hosted with ❤ by GitHub

That’s it for this synopsis. Until next episode, happy code thrashing and go coding!

Thrashing Metal Monday for Week of the 13th of May.

A new band I just learned about this last week is Bloody Hammers. Listen to those vocals, traditional dark prodding rhythms and melody. It’s eerie in the best of ways and provides that melancholy horror movie feel so well! Beautiful!

You can check out their website which has good details and information, but their material is of course out there on Bandcamp too so check that out and pick up some tunes!

Not new for regular readers of Composite Code or viewers of Thrashing Code listening sessions, but I felt another Spoil Engine tune showing some of their range would be a good kick to Monday. May it light your mind up for the week!

To wrap up the trigonous edges of metal for today, part one of the new Amon Amarth saga!