In episode 1, Miki had two functions that performed the similar operation, but returned different types. To refactor this, Miki rewrote both functions as a generic function that allowed him to specify the type to be returned during invocation. In some cases, the compiler may not recognise a type, thus, Miki gives a few pointers on manually telling a generic function which type to use. After demonstrating how to return different types with a generic function, Miki limited the types his generic function would accept with an interface.
In this video, Miki will take a closer look at the performance implications of interfaces since “there’s no such thing as a free lunch.” The first step he’ll take is to define a struct to represent weather and a function to return said type with a hard-coded value. Miki chose this example as it illustrates how a function’s variable can escape to the heap due to the use of interfaces. To better frame the previous statement, Go’s logging functions accept interface types for arguments and this is done to increase the universality of the logging function. Watch and learn how you can benchmark your code, view optimizations done by the compiler and pinpoint the variables being allocated to heap.
Things you will learn in this video
From the Ardan Community
Get your team up to date with best practices & customized curriculum.
We help you evaluate your architecture, design, structure, tech-debt and human capital.
Learn at your own pace!
Special offers on upcoming training events & our latest blog posts.
Valid email required.
Submit failed. Try again or message us directly at firstname.lastname@example.org.
Check your email for confirmation.
We've built our reputation as educators and bring that mentality to every project. When you partner with us, your team will learn best practices and grow along the way.
Years in Business
Please fill out the form below, and we'll get back to you soon.
Check your email for confirmation of your sent message. We'll get back to you shortly.
Ardan Labs Copyrights © 2023