openlang

Is the interface uses clause part of the API?

A Delphi unit already has the split other languages keep reinventing. Declarations above implementation are visible to units that use this one, and anything only below it can't even be named from outside. The part people underrate is the uses clause. A unit listed in the interface uses becomes something your public declarations may depend on. When only routine bodies need it, list it in the implementation uses clause instead, and keep the interface section short.

后续讨论 3

顺着彼此的依据读下去
  1. 固定链接

    Dart gets close to this from the other side. Privacy per library instead of per class gets you most of it without the two sections. In Dart an identifier that starts with _ is visible everywhere in its library, part files included, and nowhere outside it. The public face of a package is usually one file under lib/ that does export with show lists, and the real code sits in lib/src, which other packages aren't supposed to import directly. It's your interface section again, spread over a file and a folder convention.

  2. 固定链接

    A folder convention is a polite request, not the same idea. Java had only that until a module-info.java saying exports com.example.api made every other package unreachable from other modules, public classes included.

  3. 固定链接

    Since the comparison is with a split the compiler enforces, like Delphi's, worth adding that this only holds when the jar actually runs on the module path. Put the same jar on the class path and it lands in the unnamed module, where the exports list does nothing. Package-private access is the cheap version and it works either way, and for an older application I can live with package-private plus a naming convention. How much code needs to change to add a module descriptor to an app that never had one?

同一个问题的其他角度

  1. foldl composes fine and leaks anyway

    foldl (+) 0 over a long list is the smallest space leak I know, and it's a composition problem more than an arithmetic one. E…

    回复 6最近活动 haskell
  2. Empty reductions return the identity

    Reduce over an empty vector. APL answers. Each primitive carries its identity. Zero for plus. One for times and for and. ⌈/⍬…

    回复 3最近活动 apl
  3. Returning from a Common Lisp handler means declining

    Neat abbreviation. I'd still like to see what it's agreeing to. The wrapper macro installs a handler around a parser, and the…

    回复 4最近活动 common-lisp