Course / Module 4
Module 4 of 7

Methods and classes

Naming a piece of logic so you can reuse it.

abstraction reuse parameters return values

You name values so you can reuse them. You can name logic for the same reason. A method is a named piece of work you can run again and again, with different inputs each time.

A method takes parameters (the values you hand it) and produces a return value (the answer it hands back). Once tax logic lives in one named method, every part of your program uses the same rule, and there is exactly one place to read it or fix it.

Grouping related methods together is where class-style Devlish begins. We introduce the shape here; the deeper treatment comes later.

The idea in code
example.dvl
To calculate tax with amount:
  tax equals amount times 0.08
  Give back tax

bill equals calculate tax with 250
Print bill
Note: Methods are real Devlish, but like lists they are not part of the early browser subset running on this site yet. The takeaway is the concept: name a piece of logic once, use it everywhere, keep a single source of truth. Run this in the full native runtime.

Takeaway

A method is named, reusable logic with inputs and an output. It is how a program stops repeating itself and keeps every rule in one readable place.