I think you'd want to use "File.separator" instead of hard coding "/" for the
same reasons constants are better than hard-coded values in general.
It captures the semantic context of the constant value, for one thing. It's
clear that you intend to use a file separator character in that context. You
may be using "/" in your source code for other purposes, perhaps as a separator
in an XPATH query, or for some of the many other uses of that character.
Even though it may seem more verbose, it increases maintainability. It's the
textbook case of self-documenting code. It's also a formal refactoring
technique labeled "introduce explaining variable."
If I were doing a code review with you, I'd strongly encourage you to keep
File.separator instead of "/".
Rob
On Dec 29, 2010, at 2:54 PM, Christian Catchpole wrote:
> Yeah, that's my experience. You might need it if you are building
> paths for display or whatever. There might be some other weird
> conditions where you might need it (edit or building existing paths).
> But for something simple like new File("./path/file"); I can't see why
> you would need the File.separator
>
> On Dec 30, 3:30 am, phil swenson <[email protected]> wrote:
>> I find code that uses the "File.separator" field irritating. It makes
>> the code uglier and best I can tell "/" works everywhere, including
>> windows. Does anyone know if there is a reason to use File.separator
>> instead of just "/"? My guess is unless you are writing java code
>> that writes to a .bat file or something along those lines, "/" is
>> fine. Right?
>
> --
> You received this message because you are subscribed to the Google Groups
> "The Java Posse" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/javaposse?hl=en.
>
--
You received this message because you are subscribed to the Google Groups "The
Java Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/javaposse?hl=en.