News for hackers. Stuff that matters.
Re:Dotfile Madness by matheusmoreira on Sunday October 23, 2022 @11:30PM (#33312685)
I don't find it egregious at all. Nobody should go out of their way to integrate with Windows APIs when files work just fine everywhere.
Re:Dotfile Madness by Spivak on Sunday October 23, 2022 @11:35PM (#33312708)
It’s basically the same as looking up $XDG_CONFIG_HOME on GNU/Linux.
Re:Dotfile Madness by matheusmoreira on Sunday October 23, 2022 @11:49PM (#33312769)
That's just an environment variable while this ShGetKnownFolderPath thing is a Win32 API function. People should avoid directly depending on that stuff as much as possible.

People aren't obligated to "comply" with the XDG specification either. It's not a bug to just use $HOME.

Re:Dotfile Madness by pie_flavor on Monday October 24, 2022 @02:07AM (#33313407)
You're directly depending on platform-specific stuff the moment you look up the user directory, because it's not $HOME on Windows either.

There is a difference between being cross-platform, and being Linux but mangling it so it technically works on other platforms.

Re:Dotfile Madness by matheusmoreira on Monday October 24, 2022 @03:03AM (#33313733)
It's just a different variable: USERPROFILE.

https://stackoverflow.com/a/42700844/512904

> being Linux but mangling it so it technically works on other platforms

Sounds like the easiest way to solve this problem. I don't blame or shame developers for choosing it.

This is simple and works everywhere:

  char * home = getenv("USERPROFILE");
  if (home) {
      // Use home directory
  }
The answer demonstrating the Windows API way has the following code to accomplish the same thing:

  WCHAR profilePath[MAX_PATH];
  HRESULT result = SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, 0, profilePath);
  if (SUCCEEDED(result)) {
      // Use home directory
  }
Yeah, I seriously doubt open source developers want to deal with this Windows bullshit. I sure don't. Maybe if you're getting paid.
Re:Dotfile Madness by delta_p_delta_x on Monday October 24, 2022 @05:10AM (#33314401)
'This Windows bullshit' is merely the Windows equivalent of a veritable zoo[0] of Unix/POSIX/Linux headers and functions including unistd.h, sys/types.h, sys/socket.h, fcntl.h, sys/ipc.h, semaphore.h, stdarg.h, signal.h, pthread.h, and so on.

Just because you aren't used to it doesn't mean it's 'bullshit'. Might I provide a counterexample to the 'simplicity' of Linux? Developing video games natively on Linux is such a pain point that the industry has standardised around simply translating Windows syscalls and Direct3D shaders to their Linux equivalents, because the latter is so heavily fragmented to develop natively for. Also known as Proton.

[0]: https://en.wikipedia.org/wiki/C_POSIX_library

Re:Dotfile Madness by matheusmoreira on Monday October 24, 2022 @05:58AM (#33314659)
Whenever dotfiles are mentioned, it's safe to assume we're talking about terminal applications and that the target audience is software developers. This stuff only really matters to us, people who actually care enough about the system itself to not only use a terminal but also to bikeshed configuration formats and file system trees. That's exactly what the article this thread is about and the comment I replied to were talking about: stuff like developer tools and ssh.

Honestly I don't even disagree with you. I think POSIX sucks. I think even the libc sucks. However there is no way you can look at the Windows API mess above and think it's somehow better than the portable and clean getenv function call. Maybe you can "get used" to that cruft but I can't. If I had to deal with code like that the first thing I'd do is abstract it away so I don't have to deal with it anymore. That's exactly how Windows is and should be treated by everyone.

Video games, your counter example, are probably the most platform-specific software imaginable. There's a reason pretty much everybody uses an engine these days. There is no way you can compare that stuff to getting a user's home directory and writing files in there.

Also, for video games it ultimately doesn't matter how sucky the APIs are since it's all about market share anyway and people will use whatever they need to get it done. First parties don't put in effort into porting games to Linux because they don't see the money. Valve puts in effort because it gives them their own platform that they control and therefore leverage over Microsoft and its app store. Emulation and compatibility layers are a proven solution when first parties aren't playing ball. If they don't want to make it work on Linux, people will make it work whether they want it or not.

Re:Dotfile Madness by pie_flavor on Monday October 24, 2022 @11:43AM (#33318196)
The former does not in fact work everywhere, it only works on Windows. Once you have your #ifdef, there is absolutely no point in having the wrong Windows-specific code instead of the right Windows-specific code. Also, look at what you're describing as weird bullshit: a function call with an enum, instead of a function call with a string. The only difference is that you haven't bothered to familiarize yourself with the world outside of Linux, so it feels unfamiliar.

Also, you're comparing something it makes zero sense to compare. People are not saying 'you need to fetch $USERPROFILE without calling getenv'. People are saying 'you need to not store random garbage in $USERPROFILE'. Calling getenv("APPDATA") is a perfectly fine way of fetching FOLDERID_RoamingAppData, the same way you weren't going to bother calling getpwuid if $HOME was undefined.

Re:Dotfile Madness by matheusmoreira on Monday October 24, 2022 @04:08PM (#33321905)
> The former does not in fact work everywhere, it only works on Windows.

It's just some example code. Real code will probably try a number of variables.

> Calling getenv("APPDATA") is a perfectly fine way of fetching FOLDERID_RoamingAppData

Okay then. Top level post said you needed a Win32 function for this. If you can do that without those functions, I suppose it's easy enough to support.

> calling getpwuid if $HOME was undefined

$HOME is set by login and ssh to whatever is in the passwd database. Can it ever be undefined? Seems like something is seriously wrong if it is.

Re:Dotfile Madness by delta_p_delta_x on Sunday October 23, 2022 @11:51PM (#33312774)
> Nobody should go out of their way to integrate with Windows APIs

  int writeConfigFile(ConfigFile file) {
  #if defined(_WIN32)
      // Windows-specific function
  #elif defined(__linux__)
      // Linux-specific function
  #elif defined(__APPLE__)
      // macOS-specific function
With modern C++, there's probably a way to do this in a nicer manner, and achieve runtime polymorphism with virtual functions or a lambda (function pointer) table.

As another sibling commenter wrote, .NET already has a platform-agnostic function to write to a `user program data` folder that nicely maps to the platform-specific directories. Other GC languages (Java, Go, etc) likely have similar abstractions.

As for scripting... A cross-platform project with scripts that also targets Windows should (in my opinion) have PowerShell `.ps1` scripts accompanying any `.sh` scripts. Better still, scripting should be done in a language that's truly platform-agnostic, like Python.

Re:Dotfile Madness by matheusmoreira on Sunday October 23, 2022 @11:58PM (#33312802)
> With modern C++, there's probably a way to do this in a nicer manner, and achieve runtime polymorphism with virtual functions or a lambda (function pointer) table.

You proved my point. Creating an #ifdef mess with polymorphism, virtual methods and indirection is the very definition of going out of one's way to support something that really doesn't need any support.

Re:Dotfile Madness by delta_p_delta_x on Monday October 24, 2022 @12:07AM (#33312842)
If a developer writing in C/C++ is targeting Windows, then bringing in `<windows.h>` (and associated headers) is almost guaranteed, especially if said developer wants to work with native APIs (unless said program will rely on MinGW/Cygwin/Msys2, which are arguably worse, since they drag in an entire Linux directory tree per application).

This is just part of the cost of developing cross-platform, and I'm sorry, but to me, dismissing this as 'going out of one's way' is just being sloppy.

Re:Dotfile Madness by matheusmoreira on Monday October 24, 2022 @12:24AM (#33312920)
Are the developers of "Unix-first software (such as `ssh`)" targeting Windows though? I don't think so. They don't deserve to be shamed for this stuff. They aren't "sloppy", Windows is lucky to get ports at all.
Re:Dotfile Madness by rollcat on Monday October 24, 2022 @08:48AM (#33315968)
> #elif defined(__linux__)

I felt a great disturbance in the source, as if hundreds of BSD users suddenly cried out in terror and were suddenly silenced.

Re:Dotfile Madness by 31b3r3t7 on Monday October 24, 2022 @02:57PM (#33320822)
No need for runtime polymorphism for this. The same binary won't be used in different operating systems. This is a classic example of misuse of C++ features just because they exist and a reason why I personally prefer programming in C. What I would do in a case like this is to have three source files each implementing the function for UNIX/Windows/Mac and the build system should take care of compiling the right one into the program depending on the OS.
Re:Dotfile Madness by delta_p_delta_x on Monday October 24, 2022 @09:43PM (#33325137)
This is a much better idea, actually. You're right that what I mentioned is a bad misuse of C++ features.

I initially did think of simply letting the build system handle it (CMake can do this excellently, as can Meson, probably) by simply choosing different source files for different target OSs, but when typing out the parent comment, I forgot about it in my train of thought.

Come to think of it, this is far more elegant.

Re:Dotfile Madness by pie_flavor on Monday October 24, 2022 @02:05AM (#33313389)
The reason app developers think it's fine to dump them in $HOME is because Linux hides them. Those app developers do not bother hiding them on Windows. The specific functionality being used does not 'work just fine everywhere'. It is not the case that Linux functionality is How Computing Works with every deviation being 'out of the way', not even in a hypothetical world where Linux isn't the drastic minority of machines by an order of magnitude.
Re:Dotfile Madness by matheusmoreira on Monday October 24, 2022 @02:37AM (#33313575)
> Linux hides them

Linux doesn't hide anything. It's POSIX and GNU tools that choose not show anything that starts with a dot by default. As far as Linux is concerned they're just normal files on the file system.

It doesn't have to be that way. Personally I have my system configured so that all "hidden" files are shown because I hate the concept of hidden anything. I used to do this in Windows too.

> The specific functionality being used does not 'work just fine everywhere'.

It kind of does. "Program reads configuration from a file" seems like a really basic thing that every operating system supports. There really is no need to directly depend on any Windows API stuff. Even worse would be suggesting the use of the registry.

> It is not the case that Linux functionality is How Computing Works with every deviation being 'out of the way', not even in a hypothetical world where Linux isn't the drastic minority of machines by an order of magnitude.

And yet Windows is the system getting "half-baked ports of Unix-first software" here. Why should the developers be shamed for not going of their way to support Windows conventions for Unix software?

Re:Dotfile Madness by delta_p_delta_x on Monday October 24, 2022 @05:27AM (#33314478)
> Even worse would be suggesting the use of the registry.

I would actually argue otherwise: the registry is the perfect place to put configuration data, provided Microsoft's guidelines[0] on registry key creation/deletion and hive use are followed. I would argue every OS should have its own 'registry' for a universal location to set configuration for programs.

On the other hand, if every application has its own configuration file, then every application shall have its own configuration file parsing/serialising/deserialising routine. It's also what has led to this explosion of 'config file formats': .json, .yaml, .ini, .conf, .cfg, .toml, .xml.

I guess this is why people dislike systemd so much: it reminds them too much of Windows.

[0]: https://learn.microsoft.com/en-us/windows/win32/sysinfo/regi...

You appear to have an attitude of UNIX/Linux > Windows, which is unfortunate. The two OS families are different, but I personally believe neither is superior to the other. Both OSs suck in their own ways, both OSs are better in their own ways (this conclusion after using Windows and Linux both on a 70:30 time ratio).

Windows is in every way as modern an OS as Linux is, but just like Linux, has inherited strange baggage from its 40-year-old past, like 'a file cannot have COM in its name'.

Re:Dotfile Madness by matheusmoreira on Monday October 24, 2022 @06:38AM (#33314937)
> the registry is the perfect place to put configuration data, provided Microsoft's guidelines[0] on registry key creation/deletion and hive use are followed

Few people follow that stuff. I wouldn't be surprised if Microsoft's own people didn't follow that stuff. The result is of course a mess that users have to clean up with software like CCleaner or whatever people use these days.

It sucks even if those guidelines are followed. Configuration is data and belongs to the users. I know people who really like portable applications that they can keep on a USB drive and use anywhere and this registry bullshit breaks that.

> I would argue every OS should have its own 'registry' for a universal location to set configuration for programs.

And I would argue otherwise. The Windows registry is essentially a poor excuse for a proper file system. I think at least one Linux desktop environment tried to reinvent this crap and it sucked just as hard.

> every application shall have its own configuration file parsing/serialising/deserialising routine

The Windows registry values are essentially memory dumps of C types. It's perfectly possible to simply dump raw bytes into binary files on Linux too if you don't care about stuff like endianness. The result would be strictly superior to the Windows registry because the files are being stored in a real file system.

> I guess this is why people dislike systemd so much: it reminds them too much of Windows.

I like systemd.

Re:Dotfile Madness by pie_flavor on Monday October 24, 2022 @11:52AM (#33318328)
> Windows is the legacy proprietary system people only support because it gets them paid.

Windows is the system everyone actually uses - even developers!. I write software because I care about people using it.

> Why should the developers be shamed for not going of their way to support Windows conventions for Unix software?

Because it's wrong on Unix, and even wrong on Linux, and once you are doing the right thing on Linux it is no longer out of your way.

Re:Dotfile Madness by wruza on Monday October 24, 2022 @03:45AM (#33313962)
Regular windows users do not visit $HOME often either. They work mostly in Desktop, Documents and Downloads. They can’t even “go up” from these anymore for more than a decade. None of the non-tech users I know would even understand me if I told them to look at their homedir. So yeah, it’s fine regardless.

Btw, many native, no-linux windows apps, including Microsoft ones love to create their bs folders like “My Games”, “Microsoft Visual Studio (c)(tm) <yearname> Pile of Whatever” or “Android Projects” right in ~/Documents. This “way” is unenforceable even in OS’es own company.