Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Looking at Microsoft's C code makes my eyes hurt. I don't know if it's the style (bracket placement, no new lines), naming conventions, typedeffing away pointers, or what, but it just doesn't read easily to me.


You get used to it after a while. The NT style has an austere beauty all its own too. Typedefing away pointers creates a uniform and regular syntax --- no reading declarations forwards then backwards then forwards again. The doc comment style encourages thoughtful architecture. Opaque handle types are common, which is good.

https://computernewb.com/~lily/files/Documents/NTDesignWorkb...

Nobody likes Hungarian though.


Typedeffing away pointers means I don't know when copying or passing something if it's by value or by reference.


If it starts with LPsomething or Psomething, it's a pointer. Turns out the much-hated hungarian notation does provide value


Having your typedef be simply "something" and then using something* instead of Psomething would provide the same value and also be readable to people not familiar with your particular naming convention.


Pointer typedefs are typically useless because at the usage side you will have to declare structs on the stack and take their address anyway. So you need to be aware that a typename refers to a pointer type, and furthermore it's harder to see and really know because you have to resolve the typedef in your head instead of seeing it right there in syntax.


The combination of all-caps type names and Hungarian notation for variables (“ppszOutStr”) makes it feel like you’re having a conversation with the vampire from the 2024 Nosferatu remake.

He’s kind of yelling slowly and kind of talking in some East European language, and yet you can kind of understand what he’s saying.

(And if I ever have to open an MFC codebase again, I’m going to be thinking of how Nosferatu springs up naked and rotting from his coffin)


Notably it's Systems Hungarian which makes no sense whatsoever. This notation is a way to mention the kind of a variable in languages which don't directly express that. It starts in BCPL which doesn't have types, so if boop is a boolean and blip is a counter we need to annotate the name of the variable as the compiler doesn't see any reason you shouldn't use boop as a counter and blip as a boolean, so we maybe call them bBoop and cBlip or whatever.

Now for the team writing say Excel, they have a typed language so they don't need to distinguish booleans from counters, but their language doesn't have or encourage distinct Row and Column types, those are both just integers, so "Apps Hungarian" uses the name to annotate variables with such information, clInsert is the column while rwInsert is the row, if I am reviewing code which is to inspect columns and it checks clFooC, clBar and rwBaz well why is it using a row number for a column? That warrants closer inspection.

Unfortunately, this practice was divorced from its rationale and infected teams at Microsoft who had a typed language and didn't have kind information beyond that, but felt the need to use this notation anyway, producing "Systems Hungarian" where we mark out pFoo (it's a pointer named foo), and lBar (it's a long integer named bar). This is very silly, but at this point it has infested an entire division.


Great description of the nuance between Systems Hungarian and Apps Hungarian.

One further nuance is that return types of APIs also affect the naming of the APIs in Apps Hungarian. Boolean return values are typically called f for flag. An API that returns a boolean would be called FApiFunction - the capital F (camel case is used) at the beginning of the API name indicates that the API returns a boolean. If you write code that stores the return value in a variable that doesn't begin with an 'f' then any code reader would see the mismatch.

FTA, one problem is that the API returns a ULONG where 0 is failure and non-zero is success.

But the developer thought that the API returned an NTSTATUS error code, where 0 (== STATUS_SUCCESS) is success and non-zero is failure. This is the opposite of the documented return value for the API in question.

In Apps Hungarian, the naming of the API would be obvious that it didn't return an NTSTATUS variable vs a ULONG. Systems Hungarian lost that tidbit somewhere. So developers must be more diligent about knowing the return values of various APIS (but assuming NTSTATUS usually works, expect in this case).

But Apps Hungarian rarely names variables with native type prefixes. Variables are more than just the native underlying type (ULONG, int). Variables have a purpose. The return type of strlen or Win32 equivalent is an int or for more modern-designed APIs, an unsigned int (since string lengths can't be negative). In Systems Hungarian, you'd name the variable ulen. But in Apps Hungarian, strlen returns an int representing the count of characters. Apps Hungarian uses 'ch' for character and 'c' to denote a count. So the variable used to store the return value from strlen would be cch. (And in Apps Hungarian, you'd actually alias strlen to CchStrlen so you'd know just looking at the API that it returns a 'cch', count of characters, and you'd need a CCH type to store the return value).


And if atop of ASCII "ch" you add UTF-8 bytes and unicode character, what's the naming convention?


bytes are bytes, and in Apps Hungarian, it'd be 'b' type. So 'cb' would be a count of bytes.

I'm not sure you could place utf characters 'atop' of 'ch', more alongside/as well.

Win32 had support for wide-characters (UCS-2, I believe) which mapped to WCHAR/'wch'. They also support, in the windows.h headers, for compiling code to support both single-byte characters and wide characters using one code base via macros/typedefs with the TCHAR type et al. This resulted in code that used 'tch' as the underlying character type.

So code that only wanted 16-bit Unicode would have variables like 'wch' and 'cwch'. Code that supported both single and wide characters would have 'tch' and 'ctch'.

UTF support in Win32 appeared after I stopped Win32 programming. Looking up a few Win32 UTF-related programming docs, MS seems to have shoved UTF-8 support under the old Win32 Ansi-character/single byte string APIs. I'd probably create some Utf-type related APIs that called down to the Win32-related APIs. But it would also depend on the UTF-8 API design (strlen doesn't map 1-1 to UTF chars anymore) - parsing UTF-8 characters/code points is different than single-byte character set. I'd guess there'd be 'uch' for a UTF-8 character, probably a 'ucp' for a UTF-8 character point, etc.

[edit] You wouldn't just repurpose single-byte string code with 'cch' for UTF-8 since the semantics aren't the same (not even if you include double-byte character sets like Japanese), one UTF-8 character can be one or more bytes which typical one/double-character set string code doesn't deal with.


as a reference, the reference to 'ppszOutStr' that a previous poster mentioned wouldn't be typical Apps Hungarian.

'sz' is a null-terminated string, so naming a variable 'szOutStr' is redundant since 'sz' automatically tells you it's a string. 'szOut' would be fine. The 'pp' at the front tells you it's a pointer to a pointer. You typically only use a 'psz' to refer to a string (I usually used 'sz' since most of the time, you're dealing with allocated memory and that means I had a pointer alread).

But if you want to reallocate the string memory , you'd have to take the address of the pointer (&psz) which meant you'd have a pointer to a pointer to a string: 'ppsz = &psz;'

When dealing with a 'ppsz', you'd know that you couldn't pass 'ppsz' directly to a function that handled 'psz' variables, you'd need to dereference ppsz (*ppsz) to get a 'psz' to pass to those functions. Useful when dealing with liberal C compilers, not as useful with stricter C++ compilers.


Here's a link to a doc by Charles Simonyi describing Apps Hungarian. see https://cgtweb1.tech.purdue.edu/courses/cgt456/Private/Readi...

MSDN Library seems to have totally nuked any pre-2005-ish URLs and their search engine is just bad as well (archive.org seems to have gotten tons of 302s/301s when crawling for this article). So you'll have to make do with a copy of the MSDN Library article at purdue.edu.


Finally found a microsoft link for the Hungarian Notation article - search engines suck these days.

see https://learn.microsoft.com/en-us/previous-versions/visualst...


For all the people who say to me “yOu DoNt NeEd RuSt”, you can have your tyre fire languages where you need to build SOCIAL ABSTRACTIONS on top of the language because your type system literally came from the 1970s.

… I don’t know, I kind of like my compiler catching issues like these rather than having to do it by eye and hoping for the best


Syntax coloring and click nav in IDEs made Hungarian totally obsolete, and ms also took it to an extreme.

I used to have different hungarian prefix conventions for local, global, argument and instance vars.

I actually still use them sometimes


it's worth noting as well that the windows API has been a thing since 1985, _before_ C was standardized, such old versions of C were incredibly untyped


No. Where BCPL doesn't have types, C does have types. They're not very good types, we're not going to get any prizes in a language design class, they're basically all the machine integers wearing fancy dress, but they are types.

You know how in C you can write "int k" or "char v" ? That's types. BCPL doesn't have that. Yes that's in the original K&R book, no you didn't need to wait until 1989 to have types in C, they were obligatory from the outset.


The case of the company that writes overly verbose code and decides to change the meaning of names and constants between different libraries that actually do the same things.

Microsoft saw all the footguns available and decided to just incorporate every one they possibly could and invent new ones whenever possible. For extra hilarity they put all this in a monorepo for all the good that has /never/ apparently done for them.


Hungarian notation had a purpose to it, but then they went and did it wrong accidentally (there's an old Joel on Sw article about it, but I'm not linking it) - and in the example this is all over the place - not to mention C macros ooofffff

But yes the mix of that plus camel case, make things confusing



Did fogbugz ever hit it big? Joel's blogs are legitimate gold and almost timeless (AIpocalypse tbd).

But they just did bug tracking and other jira type stuff in MS land, right?


not that I know.

They also did Trello. No idea if they got paid big for spinning off/selling Trello.

There was also some vncviewer/rdp client-type thing (copilot) which was more consumer-friendly - relatively quick install/didn't spew files/garbage all over your disk/registry.

He also co-founded stackoverflow, so I thought there was a big payday when stackoverflow got bought.


Every facet of Microsoft seems to lack style. Every official/affiliated blog is ugly and inconsistent. C# looks ugly to me. Windows is fugly. Their fonts are horrid. It's to be expected


Partial disagree: Yes their blogs may be ugly.

But C# is extremely beautiful, you can read and write it like a novel.

Segoe UI is also not the worst font. I give it a 7/10.


C# in Visual Studio is ugly with Windows font rendering, to me

I find the title case ugly, not a fan of semicolons, nor the new keyword. Guess I'm too used to Kotlin and Linux/Mac fonts


Your complaint is not about C#. You're complaining about fonts and saying C# itself is ugly.


They are saying that those particular fonts with that particular kind of font-rendering engine (windows), doesn’t work for them for that particular language.

It’s a conjunction of all 3 things.


And none of them have anything to do with the language. You don't need windows, don't need visual studio, and you can choose whatever font you want.


Sure, but if you read their comment, it is conditioned on all of those aspects together. It's not about the language, as is, but all of them together. Is it a useless comment? absolutely! But that's beyond the scope of this conversation.


You do realize which IDE or text editor to choose and which fonts to use with either is a choice?


well, C# and TypeScript is thanks to Anders Hejlsberg who does have sense of style.


But C# is extremely beautiful

Seriously? It's basically Microsoft-flavoured Java, and has much of the same horrid verboseness and architecture-astronaut overcomplexity.

K&R, early UNIX style, BSD is what I find "extremely beautiful".


I work at Microsoft, so I'm biased, but C# may be my favorite language I've worked with compared to C++, Python, Type/JavaScript, Java, C, etc.

I see/hear jokes often that it's Microsoft Java, and yeah definitely granted that it comes from the same origins, but it's got some of the greatest tools I've worked with, best documentation, and best support I've seen. Anytime I've asked myself "Can I do this with C#?", the only times the answer has been "no" is when looking for a C++ constexpr equivalent (closest you get is build-time code-gen, which ain't half bad), or discriminated unions (inexplicably).

I'm convinced that anyone who complains about C# has never used it.


Think Steve Jobs once said something to the effect of Microsoft having no taste. I think I’d agree. Inconsistent design language, inconsistent values, inconsistent vision.


Yet they've had astounding success and is the most widely used operating system. Maybe usability and ease of access are far more important than beautiful design


You can succeed despite poor taste, but that doesn't make your taste any less poor.


Design _is_ usability and ease of access.


I think it is marketing and sales muscle that leads to ease of access.


Shockingly, monopolies and entrenchment in software is SUPER EFFECTIVE.

While MS isn't utterly technically bereft obviously, and they had some correct choices like backward compatibility and usability relative to imbeciles like IBM, just look at the botched execution of Win8, their security disasters, and generally superior products that got nudged out by beta-ware quality releases.


I don't have any problems with the way Windows looks. I'd ask you what operating system looks better. And if the answer is macOS, I'd agree with you, I'd say yes, a painting can be pretty too, and about as useful as macOS.


Early Windows looked good, but not anything Win8 or newer.


I don’t see how windows has any form of prowess over macOS. I find the latter much better for my usecase.


If you think their fonts are ugly now, you should go back and look at the pre-Windows 3.x fonts. But you also have to realize they were saddled with CGA/EGA as their target display adapters back then.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: