Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between path & path.filepath packages in Go

Tags:

path

go

filepath

I have found that there are lots of similar function in the package path and the package path/filepath. I have tried several common paths like /var/log/something but did not find any differences. When should one use path directly and when should one use filepath instead?

like image 511
waitingkuo Avatar asked Aug 27 '16 13:08

waitingkuo


People also ask

What is the difference between path and path?

1) PATH and Path are the same since Windows environment variables are case insensitive (File paths in Windows environment not case sensitive?). 2) Windows use Path to locate executables that are not located in the "current folder".

What is the difference between path?

The path difference is the difference in the physical distance between the two sources to the observer, i.e., the difference in distance traveled from the source to the observer.

What is difference between path and CLASSPATH?

The main difference between PATH and CLASSPATH is that Path is set for java tools in java programs like java and javac, which are used to compile your code. Whereas CLASSPATH is used by System or Application class loader to locate and load compile Java bytecodes stored in the . class file.

Which of the following statement is correct difference between path and CLASSPATH?

1). Path is an environment variable which is used by the operating system to find the executables. Classpath is an environment variable which is used by the Java compiler to find the path, of classes.ie in J2EE we give the path of jar files.


1 Answers

What is the difference?

While functionally similar, path and path/filepath offer differing implementations. Filepath depends on the os package to choose the target runtime's file separators and other differing components when dealing with path strings.

You can look as the os source to see that there are differing implementations for various utility functions. This allows operating system specific details to be abstracted away by the library and helps achieve portability. The path/filepath dependency graph illustrates how the package depends upon the os package. You can compare this with the path dependency graph. I would encourage you to go into the filepath and path source code to observe this relationship.

When do I use each?

You should use filepath when working with files. This ensures your paths will be matched with actual files regardless of the underlying runtime. The path library should be used within models or when paths may be serialized or communicated with other programs. This ensures that a single formatting scheme is used regardless of what platform the programming is running on. Having a consistent format makes reasoning about models more generic and easier to understand.

like image 153
Ben Campbell Avatar answered Oct 19 '22 05:10

Ben Campbell