from Hacker News

Walter Bright: Crafting Self-Evident Code with D [video]

by open-source-ux on 10/24/23, 8:08 PM with 2 comments

  • by peter_d_sherman on 10/24/23, 9:25 PM

    There is some serious programming wisdom in this video! For that reason, it is worth re-watching in the future. What follows is a highly abridged list of some of the relevant takeaways from various time points in the video:

    06:54 Don't try to make one language look like another

    07:34 Don't reinvent bool

    10:36 Code flows from left to right, top to bottom

    13:31 Reduce conditionals

    14:59 Avoid negation

    19:31 Simplify compound if conditionals

    21:39 Reduce the number of casts

    22:57 Use self-documenting language features

    25:56 Pass an abstract sink for a function's output

    27:58 Pass files as buffers rather than filenames to be read

    30:34 The caller, not the callee, should call the environment

    31:45 Callee writes to buffer, caller writes to file

    32:30 Use function pointers (or templates)

    34:10 Functions should be in one of two categories, not both

    35:48 Line things up

    36:43 Use ref instead of *

    Of these, I think I find:

    "25:56 Pass an abstract sink for a function's output" -- the most potentially interesting...

    Why? Because it can almost be thought of as borderline functional programming -- within an Imperative and/or Object-Oriented programming language... at least as far as the function using this method goes... it also has a wide variety of applications, i.e., instead of having a function do memory allocation (requiring that memory to be freed somewhere else in the program), why not pass such a function an additional memory allocator function pointer or object -- where the allocation (and subsequent deallocation) of memory -- is managed in some other well-defined place in the code...

    Anyway, it's a great video! Well worth watching!