publicvoit,
@publicvoit@graz.social avatar

What happens, when you join two paths in a language when the second one is an absolute one?

join("foo", "/bar")
returns "foo/bar" or "/bar"?

The wonderful @meisterluk wrote a great article about that you might want to read: https://lukas-prokop.at/articles/2024-05-03-filepath-join-behavior

I can not tell what version I'd actually prefer. There are situations where both versions would be "proper".

#C++

soc,
@soc@chaos.social avatar

@publicvoit @meisterluk Neither of those choices is correct.

The right solution is using the type-system to prevent obviously wrong code from compiling:
✅ join(AbsolutePath, RelativePath)
✅ join(RelativePath, RelativePath)
❌ join(RelativePath, AbsolutePath)
❌ join(AbsolutePath, AbsolutePath)

Another benefit is that AbsolutePath is not restricted to the root of the filesystem, but could express things like "the user's cache directory", increasing portability of paths saved to config files.

publicvoit,
@publicvoit@graz.social avatar

@soc @meisterluk Well, that's not something the compiler is able to decide when the parameters are not known during compilation.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • programming
  • rosin
  • thenastyranch
  • mdbf
  • DreamBathrooms
  • InstantRegret
  • magazineikmin
  • Youngstown
  • cisconetworking
  • slotface
  • vwfavf
  • everett
  • Durango
  • kavyap
  • GTA5RPClips
  • megavids
  • khanakhh
  • osvaldo12
  • ngwrru68w68
  • anitta
  • normalnudes
  • ethstaker
  • cubers
  • modclub
  • tacticalgear
  • provamag3
  • Leos
  • tester
  • JUstTest
  • All magazines