Hacker News new | ask | show | jobs
by moserware 3720 days ago
Do you remember any details from Cutler Normal Form? I'd love to learn more about this.

From a quick search I see that it uses braces at the end. I'd be curious if CNF encouraged subsystem prefixes (e.g. the "Ke" in "KeBugCheck").

I wonder if CNF had any influence on "Systems Hungarian" (e.g. "dwCreationFlags") that dominates the Win32 API or if that came as an accidental offshoot of Simonyi's "Application Hungarian"

1 comments

I don't remember much hungarian in CNF, I do remember a lot of whitespace...

  //
  // Comments are always surrounded both by empty comment lines
  // And by whitespace
  //

  //
  // The return type is always on its own line.
  // The function name always starts at column 0 and is whitespace delimited,
  // this (allegedly) was a consequence of search macros that Cutler used
  //
 
  int
  main (
      int argc,
      char **argv)
  {
      //
      // Even a one line comment ends up taking up at least 4 lines
      //

      printf("Hello, World!\n");

      if (argc == 2)
      {
          //
          // All blocks always use braces
          //
      }

      return 0;
  }
Cutler Normal Form has open braces at the end of the line, so it should be

    if (argc == 2) {
   
        //
        // explanatory comment
        //
    }
Also, Dave hates Hungarian notation of any flavor.
Thanks for the example! I especially found the commenting style and return type on its own line to be interesting.

Regarding placement of curly braces, did you see them on their own line or at the end? This article seems to imply that CNF had braces at the end: https://blogs.msdn.microsoft.com/peterwie/2008/02/04/pedanti...

I'm interested because it seems that lower-level systems programming at Microsoft put braces at the end (early .NET BCL, maybe even the first C# compiler's C++ code, TypeScript compiler source, etc), but that Microsoft documentation tended to put braces on their own line and then that became the more de-facto style that shows up in their open source code.

I also used to work at Microsoft. CNF was primarily used in the kernel and driver code but rarely in userland code, with the exception of certain tools that were developed and maintained by the kernel team (such as powercfg.exe). CNF was one of the few coding styles at Microsoft that I really enjoyed using due to how clean and disciplined it made the code. I felt that the style really reflected Dave Cutler's attention to detail and quality.

You can see more examples of CNF in the now open-sourced Windows-Driver-Frameworks: https://github.com/Microsoft/Windows-Driver-Frameworks

I've recently adopted CNF for Windows-based C work and I absolutely love it.
My recollection is that almost all the code I wrote at Microsoft used Allman style, the only exception that I remember was Midori which used K&R

https://en.wikipedia.org/wiki/Indent_style