Posts

Showing posts from November, 2025

Python by Structure: Property Decorators and Managed Attributes

Image
  Python by Structure: Property Decorators and Managed Attributes # python # coding # programming # software Timothy was adding a  Rectangle  class to a geometry library when he ran into a design problem. "Margaret, I need an  area  attribute on my rectangles, but the area depends on width and height. Should I calculate it in  __init__  and store it, or make users call an  area()  method every time?" Margaret looked at his dilemma. "Neither. You want the area to look like an attribute but calculate itself automatically. That's what the  @property  decorator does." "Wait," Timothy said. "I thought decorators were for wrapping functions or transforming classes. How does a decorator make something look like an attribute?" The Problem: Methods or Attributes? Margaret showed him the traditional approach: class Rectangle : def __init__ ( self , width , height ): self . width = width self . height = height ...

The Secret Life of Go: Structs

Image
  The Secret Life of Go: Structs # go # coding # programming # softwaredevelopment Chapter 6: Building Your Own Types Monday morning arrived with the scent of rain on concrete. Ethan descended the familiar stairs, coffee tray in one hand, a white bakery bag in the other. Eleanor looked up from her laptop. "What's the occasion?" "Croissants. The baker said they're architectural—all those layers held together by structure." She smiled. "Perfect. Today we're building structures of our own. Sit." Ethan set down the coffees and took his seat. "Structures?" "Structs. Go's way of creating custom types that group related data together. Until now, we've used Go's built-in types—int, string, bool, slices, maps. Today, we make our own." Eleanor opened a new file: package main import "fmt" type Person struct { Name string Age int } func main () { var p Person fmt . Println ( p...