Learn coding in Python, Go and Rust from Serdar Yegulalp, software dev specialist and senior writer at InfoWorld.
Python's built-in profiling tools only provide information at the function-call level. A third-party utility, line_profiler, can shed light on what specific lines in your code take up the most runtime. Learn how to analyze your programs with line_profiler in this quick introduction. line_profiler is hosted on Github at https://github.com/pyutils/line_profiler and on PyPI at https://pypi.org/project/line-profiler/
Anonymous functions in Go let you define a function in-line, in the context of another block of code. Learn how anonymous functions can be used, and what advantages they can provide over regular named functions.
Mypyc, available in the mypy package, lets you compile Python modules into C extensions. With the right type hints, ordinary Python code can be sped up by anywhere from two to twenty times, or even more, depending on the job at hand. Learn in this video how to get started using Mypyc for low-effort performance boosts.
Arrays and vectors in Rust let you group together collections of elements in contiguous blocks of memory, but have different behaviors. Learn how to choose between an array or a vector when creating Rust data structures -- how arrays give you a predictable compile-time structure, while vectors are more flexible at runtime.
The third-party Gorm library gives Go developers a convenient set of abstractions for working with databases, without having to write raw SQL. Learn in this introductory video how to set up and query a simple SQLite database with Gorm, which also supports a wide variety of other common database systems.
Numpy gives you fast operations for analytics and datq science, but there are times when you want to go even faster. Learn how the Numba just-in-time compilation system can be used hand-in-hand with Numpy to speed things up even further.
Rust's match keyword lets you make decisions based on the contents of variables. But it can also be used to make decisions based on a variable's type, too. Learn how using match with the Option type allows you to use types at compile time to improve the performance and safety of your code.
Many languages offer "nullable" variables, which can be set to some value, or nothing at all. Rust's Option type provides a safe and powerful way to encode a given variable as nullable. Learn the basics of using Option and its .unwrap methods here. (A future video will explore the use of Option with the match statement.)
The "del" keyword in Python is the source of much misunderstanding. What does it actually do, and where do you want to really use it?
Go includes in its standard library packages for generating text and HTML from templates, which can be simple text strings or sets of templates read in from files. Learn how to generate templates for basic output, such as in the console or to text files, and how to create more elaborate HTML-escaped output. For details about the use of each, see the official Go language documentation: https://pkg.go.dev/text/template https://pkg.go.dev/html/template
Enums in Rust let you create variables that can be one of a set number of types, and make decisions at runtime based on what type has been selected. This video introduces you to enums, and outlines how they make it possible to write correct and predictable code in Rust.
Python's async functionality lets you weave together many overlapping tasks efficiently, but can be tough to get a grip on. The third-party async library Trio offers convenient metaphors for creating, executing, and managing collections of async tasks.
Python has no native mechanism for bundling apps for redistribution, so various third-party projects have filled the gap. The Nuitka project compiles a Python program to a single, redistributable binary package. In this video we walk through the basics of using Nuitka to build a standalone version of an app with library dependencies and data files.
Get to know Rust's struct type, which resembles the same concept in C or C++, but also uses Rust's specific memory management metaphors. Learn in this video the basics of creating and populating structs with data, and how to work with mutable and immutable struct instances.
Numpy's a common way to perform fast math on arrays in Python, but sometimes even Numpy can use a speed boost. Learn how Cython, the Python-to-C compiler, can be used to speed up Numpy interactions even more.
Slices in Rust give you a view into a collection, such as the data in a string, or an array. But slices also must follow Rust's memory management and borrowing rules, as you'll learn in this introduction to the basics of slices.
Reflection is when programs can analyze their own data types at runtime, and act on that information. Learn how to use reflection in Go by way of the reflect package and using the empty interface, and the significance of types versus kinds when using reflection.
Normally, Python modules get imported by way of a statement in source code, but Python provides the importlib module to programmatically control imports. Learn how to use importlib to selectively import modules on demand.
Rust's memory management model features the concept of "borrowing", where the ownership of a given variable that needs mutating must be explicitly transferred. Learn how borrowing is embedded in Rust's syntax, and how the compiler prevents you from running code that violates borrowing rules.
Python's "all" and "any" keywords let you test if all, or any, elements in some collection satisfy some condition. This video shows you how to use this efficient and powerful built-in, and make sense of its potentially unexpected behaviors.
Rust's memory management model uses a concept called "ownership", where a given object in memory can only be handled by a single variable at a time, and the programmer must be explicit about how ownership is held and transferred. This video introduces the concept of ownership and gives some basic examples of how it operates.
In the inaugural video for our new series on Rust development, we'll take a look at the basics of a Rust program, and how it demonstrates many of Rust's features: mutable and immutable values (as part of its memory management model), macros, and Result types for making decisions and handling errors.
The assert keyword in Python helps guard against bugs in the development process, but it isn't a substitute for other, more proper programming practice. Learn how and when to use assert correctly in this video.
Fast and simple-to-build network services are one of Go's strengths. Learn how to create a basic RESTful JSON API in Go, using both Go's native components and the third-party httprouter package.
The new adaptive interpreter feature in Python 3.11, described in PEP 659, makes many common code patterns faster, sometimes by as much as 20%, with no effort on your part. See for yourself how 3.11's changes accelerate Python programs.
Learn the basics of working with SQL-compatible databases in Go -- how to connect to, query from, and execute actions on SQL databases. You'll also learn about the need for a database-specific driver (we use MySQL as our example), how to manage errors with connections, and how to work with either single results or multiple ones.
PyScript lets you use Python as a scripting language in webpages, using a full copy of the Python runtime running in Webassembly. Get a first look at this highly experimental but promising new technology. You can try out many of these examples in your own web browser at https://pyscript.net/examples/
Go programs allocate memory based on how variables behave. Learn how to use Go's native tooling to determine where memory allocations are made, and how to keep them from affecting performance. Image credits (from Unsplash): Pancakes: Brigitte Tohm Bicycle: Max Bender Legos: Rick Mason Car: Spencer Davis
Python doesn't just let you create your own datatypes with classes. It also lets you create your own custom mini-formatting language for each of those datatypes, as used through f-strings and the .format() function. Learn how to create a simple formatting minilanguage with this quick tutorial.
Waitgroups let you take multiple goroutines and run them all to completion. Learn how to use this synchronization mechanism to keep the async and sync parts of your Go applications in harmony.
Python's datetime type (and datetime module) give you tools for working with date and time values. Learn how to use datetime to record and create dates and times, make timezone adjustments to them, and calculate intervals between dates and times with the timedelta object type.
The Gin web framework for Go provides a fast, low-profile way to develop web applications, with routing, templating, and other common features included. Learn in this video how straightforward it is to set up a basic web app or JSON endpoint.
Python programs can be difficult to bundle up and transport to other systems, because of the dependencies that need to travel with them. The zipapp module in Python, and related projects like Shiv, create bundles from Python apps -- and in Shiv's case, include dependencies as needed.
Go's error handling system lets you create custom error types for use in your applications, which can contain detailed information about what's gone wrong and how to handle it. Learn in this video how to build custom errors and employ them in your Go programs.
Go's type system lets you create new types with their own behaviors attached to them. Learn in this video how behaviors can be passed along between types using composition, and how Go's type system design favors inheritance over composition.
If you pass command line arguments to a Python script, it's easy to extract and use them with sys.argv. But if you want to build elaborate handlers for command-like arguments, the argparse module in Python's standard library gives you rich tools for doing that. Learn here how to add command-line argument handling to your script in both easy and powerful ways.
How do Go programs handle dates and times? Learn about the use of the time package to work with the current date and time, create date and time values programmatically, format date/time values, and work with timezones. (NOTE: In this video I incorrectly refer to the "time module"; it is more properly referred to as the "time package".)
Python's built-in pickle library lets you take nearly any Python object, serialize it to a bytestream that can be saved to disk or sent over the network, then reconstructed at the other end. Learn how to work with it and what scenarios it's best for.
Learn about the details of the string type in Go -- how data are stored in them, how they can be represented as bytes or characters, and how the "rune" type in Go is used with strings.
In this introduction to Python's Pillow image processing library, we'll look at how Pillow makes common image processing jobs easy -- resizing, compositing, converting formats, and modifying image data.
The "Stringer" interface in Go lets you make any custom struct type into a printable object with your own defined formatting. Learn how to make use of this handy behavior in your own code.
Cython compiles Python to C for speed, but has traditionally used a cumbersome custom syntax. Learn in this video about Cython's "pure Python" mode, a way to use Cython with regular Python syntax so you can continue to use your existing Python tools with Cython modules. You can find the code for the example shown in this video at this URL: https://github.com/syegulalp/conway-2022
The PDM project for Python lets you manage packages used in your projects without having to create a virtual environment, using the PEP 582 standard for how to install packages locally to a project. Learn how to get started with PDM and set up a simple project in this basic walkthrough.
Go 1.18 introduces "generics" -- a powerful new way to write functions that can accept multiple types instead of only handling input of a single type. Note that the code in this video will only run in Go 1.18 or higher.
Learn how to use Python's docstrings feature to embed documentation directly into your code, available through Python's help system and accessible by third-party documentation-generation tools.
Go modules can have their code subdivided into packages, for better maintenance and program management. Learn how to refactor a basic program with a few structs and methods into the main program logic in one file, with the structs and methods in their own package.
Python 3.10's new explicit type aliasing feature makes it easier to hint types that haven't even been declared yet, such as for methods in classes. Learn how to use them in this demonstration, along with some ideas for their use cases.
Methods in Go let you attach behaviors to custom types, such as structs. Learn the basics of how to create and use methods, including how to work with values that are passed as pointers if you need to modify their contents.
Python 3.10's new "ParamSpec" type hinting function lets you pass the type hints of function parameters to other parameters, to make it easier to typehint decorators and other highly abstracted constructions.
Go's "empty interface" type allows you to work with variables that could be of any type. Learn how this can be used to construct functions that accept any variable type, and how to use type assertions that the variables in question are of a certain type.