Programming Leftovers
-
Object Ownership
Last time we touched upon object lifetime and today we wrap up the basics with a bit of a spicy topic of object ownership. We covered the lifetime quirks, and we found out that manual memory management can be a nightmare, even if we
new
anddelete
in the correct order. There must be something better than that. Well, there is but it comes with its own can of worms.Structured cleanup
Since we know the rules of
new
anddelete
, namelynew
allocates anddelete
destroys, we never really cared about who is responsible for the object. This caused a lot of confusion in the past. For instance, some API codes from Win32 return strings that should beLocalFree()
d, likeFormatMessage
orGetEnvironmentStrings
. POSIX, on the other hand, hasstrdup
as a common example of you should free it yourself. This model is confusing because you may have a lot of return statements, before which you should always callfree
ordelete
, depending on the operation. However, we have RAII since the very beginning of C++, which adds constructors and destructors. So, in 1998 resourceful people decided to addauto_ptr
to the standard. -
How to Count the Number of Rows of SQLite Table in Python?
SQLite users can use Python to create and manipulate SQLite databases, such as counting the rows in a table.
-
Understanding the Python For Loop: A Beginners Guide
Python, renowned for its simplicity and readability, offers a plethora of control flow structures that facilitate the creation of diverse programs. Among these structures, the ‘for’ loop holds a significant place due to its versatility and widespread usage in repetitive tasks.
-
Swing Music is a Web-Based Self-hosted Music Player written in Python
Swing Music bills itself as a cooler Spotify. That caught my attention. Unlike Spotify, it's not a streaming service.