FIND YOUR NEXT FEW LINES

Results for “Function scope & composition”

Small, practical examples. Search by task or narrow things down below.

137 snippets foundClear filters
PythonFunctions & error handling

Handle an expected child-process failure

Python: Catch CalledProcessError when check=True reports a nonzero exit status.

Python✓ Tested
RustFunctions & data types

Implement a method on a struct

Implement a method on a struct in a complete Rust program using the standard library.

Rust✓ Tested
CStructures & function interfaces

Initialize structure fields by name

C: Designated initializers make field assignments independent of their declaration order.

C✓ Tested
GoFunctions & types

Inspect a value with a type switch

Inspect a value with a type switch using a complete Go program with explicit sample inputs.

Go✓ Tested
CStructures & function interfaces

Iterate over a fixed array of records

C: Compute the array element count with sizeof at the point where it is still an array.

C✓ Tested
CSSResponsive conditions & sizing

Keep a viewport-relative size above a minimum

CSS: Max selects the larger of the candidate lengths.

CSS✓ Tested
CStructures & function interfaces

Keep caller data unchanged by passing a structure by value

C: A value parameter is a copy of the original structure.

C✓ Tested
GoFunctions & types

Mutate a struct through a pointer receiver

Mutate a struct through a pointer receiver using a complete Go program with explicit sample inputs.

Go✓ Tested
PythonFunctions & error handling

Parse a typed command-line option

Python: Use argparse to validate and convert an integer option.

Python✓ Tested
PowerShellFunctions & parameter validation

Pass a block of behavior as an argument

PowerShell: Invoke a scriptblock with the call operator and an explicit input value.

PowerShell✓ Tested
PowerShellFunctions & parameter validation

Preserve a failure after local cleanup

PowerShell: A bare throw inside catch rethrows the current exception.

PowerShell✓ Tested
PythonFunctions & error handling

Raise and catch a domain-specific exception

Python: Give a validation failure its own exception type so callers can handle it narrowly.

Python✓ Tested