ProgrammingPro #1: LLMOps, Power of Reduce Function, Tech Interviews, and Writing Immutable Code in Go
Hi,
Hello and welcome to the very first issue of the ProgrammingPro newsletter! In this newsletter, we’ll be detailing the most relevant industry insights, actionable and practical tutorials, and useful tools and resources for developers and engineers.
In today’s issue:
News and Analysis
Secret Knowledge: Articles & Trending Repos
Tutorial: How to Write Immutable Code in Go
Developer Career Resources
You’re receiving this newsletter because you’ve previously provided Packt with your email. We hope that you find this newsletter valuable and informative, and a way to stay up to date as new AI technologies change the world around us. If it’s not the right area for you, please click on the unsubscribe button at the footer of this email. Please also consider taking the short survey below to share your thoughts and you will get a free PDF of The Applied Artificial Intelligence Workshop upon completion.
Kind Regards,
Kartikey Pandey
Editor-in-Chief
LET US KNOW WHAT YOU THINK. GET A PACKT BOOK PDF!
News and Analysis
Go Enters TIOBE Top 10 Index, Python Still the Language of Choice: Go has entered the TIOBE top 10 index. Engineers appear to love Go, but what makes it stand out? Go is not revolutionary, but its strength is in combining the right features. It has built-in concurrency and garbage collection, is statically typed and has good performance.
Django 4.2 Released: This version has been designated as a long-term support (LTS) release, which means that security and data loss fixes will be applied for at least the next three years. It will also receive fixes for crashing bugs, major functionality bugs in newly-introduced features, and regressions from older versions of Django for the next eight months until December 2023.
New Library Updates in PyTorch 2.0: Learn what’s changed in the newly released PyTorch 2.0 library. Includes new data collectors, augmentation operators, vision features, and loads more.
Takeaways from Stanford’s 386-Page Report on the State of AI: Writing a report on the state of AI must feel a lot like building on shifting sands: By the time you hit publish, the whole industry has changed under your feet. But there are still important trends and takeaways in Stanford’s 386-page bid to summarize this complex and fast-moving domain.
Secret Knowledge: Articles & Trending Repos
Reduce - The Power of a Single Python Function: While Python is not a pure functional programming language, you still can do a lot of functional programming in it. In fact, just one function - - can do most of it and this article shows you all the things one can do just with reduce.
No-async async with Python: Learn how Textual accomplishes async-agnosticism. A (reasonable) criticism of async is that it tends to proliferate in your code. In order to await something, your functions must be async all the way up the call-stack. Textual is an async framework, but doesn’t require the app developer to use the async.
How to Improve Performance in Git - The Complete Guide: Repositories never get smaller! As times goes by, people join and commits keep being added. Simple actions, like running git status or adding new commits, start taking longer than before. Now what? Find out how you can improve performance in Git.
engshell: engshell enables large language model (LLM)-powered English-language inputs for shell in any OS.
openplayground: openplayground is a large language model (LLM) playground that can run on a laptop and allows users to leverage a variety of language models. Multiple models can be run side-by-side for comparison purposes.
High Level LLMOps Architecture: What does it take to integrate an LLM within your infrastructure? Explore components that might make up an LLMOps infrastructure beyond the usual training/inference pipelines.
Tutorial: How to Write Immutable Code in Go
Immutability is a powerful concept that we can apply to the programs we write. But it also appears as a concept for the data that we store. If we are writing software that deals with extremely sensitive data, such as an Electronic Health Record (EHR), we likely want the data to be immutable. That is to say, whenever some information in our EHR changes, we want this change to be completely traceable. That way, the entire history of your EHR is visible at any time.
When we talk about immutability in Go, we are specifically focusing on how to have immutable structs in our code. At the core of this, we have to take a look at how Go uses pointers and the difference between pass-by-value and pass-by-reference. This is something that trips up new Go programmers, and there is a sufficient amount of edge cases where even more seasoned Go programmers will occasionally shoot themselves in the foot.
In essence, it comes down to whether or not we are using pointers in our code when passing around structs to functions. If our code is entirely free of pointers, then we would also be writing immutable code.
To demonstrate this, take a look at the following piece of code. We have a struct to define a person, and a function to change the name of this person:
type Person struct {
name string
age int
}
func main() {
p := Person{
name: "Benny",
age: 55,
}
setName(p, "Bjorn")
fmt.Println(p.name)
}
func setName(p Person, name string) {
p.name = name
}
The outcome of this function, perhaps contrary to expectation, is Benny. The function setName has not changed the name of the Person object. Eventually, we all get used to the idea that to update structs in a function, we need to use a pointer instead:
func main() {
p := Person{
name: "Benny",
age: 55,
}
setName(&p, "Bjorn")
fmt.Println(p.name)
}
func setName(p *Person, name string) {
p.name = name
}
Now, when we run this code, the output is Bjorn, as we expected. The difference between these two examples is that in the first example, we are using pass-by-value, while in the second, we are using pass-by-reference.
If we look at what is happening in the first function, we will see that our Person object is being copied and that this copy is then passed to the setName function. Thus, every operation that we do on this struct is happening on the copy itself, and not on the actual object. However, in the second example, by using a pointer, we have access to the actual Person object and not just a copy. Under the hood, the second example passes an address (pointer) to the struct. The syntax of Go obfuscates some of the pointer referencing and dereferencing for us, which makes it seem like a rather small change.
In general, we want to keep our code immutable. Hence, we want to avoid using pointers in our code. How, then, do we update our structs? The setName function provides useful functionality to our system. Recall that although we cannot change the state of the objects we are using, we are still free to create and destroy them. The solution is to create a new object that has all the properties of our original object, with some changes applied. To continue our previous example, let’s refactor the setName function to achieve the desired functionality:
func main() {
p := Person{
name: "Benny",
age: 55,
}
p = setName(p, "Bjorn")
fmt.Println(p.name)
}
func setName(p Person, name string) Person {
p.name = name
return p
}
In the preceding example, you can see the core change in which we need to update structs without breaking our immutability concern. We achieve this by having functions accept copies (pass-by-value) as input and return a new struct with the changes applied. In our calling function, we now have the choice of whether or not to keep both objects or discard the original and keep only the newly returned object.
This syntax should be quite familiar to Go programmers, as this is similar to what we do when working with slices. For example, if we wanted to add a value to a slice, we would write code like the following:
func main() {
names := []string{"Miranda", "Paula"}
names = append(names, "Yvonne")
fmt.Printf("%v\n", names)
}
This code would return [Miranda Paula Yvonne]. When working with immutable structs, our syntax will look similar to this.
This tutorial is an extracted piece from the book Functional Programming in Go written by Dylan Meeus and published by Packt Publishing in March 2023.
Developer Career Resources
How to Approach a System Design Interview: New to system design interviews? System design interviews can be overwhelming due to the vast number of topics to study. This guide will teach you those key concepts in depth to increase your odds of excelling during an interview.
JavaScript Algorithms and Data Structures: Popular algorithms and data structures implemented in JavaScript with explanations and links to further readings.
Tech Interview Handbook: This repository has practical content that covers all phases of a technical interview, from applying for a job to passing the interviews to offer negotiation. Technically competent candidates might still find the non-technical content helpful.
The Real "Must Have" Tools for Programmers: The most important productivity tool for programming is your mind. And the next best set of software development tools are ones that take care of you.


