-
Notifications
You must be signed in to change notification settings - Fork 899
Refactor DirectoryHelper #1022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor DirectoryHelper #1022
Conversation
} | ||
|
||
private static void NormalizeAttributes(string directoryPath) | ||
{ | ||
string[] files = Directory.GetFiles(directoryPath); | ||
string[] dirs = Directory.GetDirectories(directoryPath); | ||
var files = Directory.GetFiles(directoryPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may be picky, but I'd rather not hide types here.
I don't like those var changes. Hiding types from stuff that's not clear from the right side of the expression is just not my style. |
I'm not precious about these changes. Unless anybody else votes for keeping them, I could roll them back. |
On the other hand, you could also say the variable names are suboptimal and, therefore, the type helps understand what these really are. For example, would you still disagree with the change if we used more descriptive variable names, like so?
From my point of view, it would make sense to rename these variables even if we roll back the previous change. @nulltoken What do you think? |
👍 We indeed tend to use
|
75f0e85
to
4e4b1b7
Compare
@Therzok and @nulltoken I've rolled back those changes but renamed the variables to be more explicit about what those really are. |
@@ -15,6 +15,8 @@ public static class DirectoryHelper | |||
{ "gitmodules", ".gitmodules" }, | |||
}; | |||
|
|||
private static readonly Type[] whitelist = { typeof(IOException), typeof(UnauthorizedAccessException) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this moved? :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To have all fields at the top of the class. The other existing field also did not directly precede the (only) method in which it was used. In other words, consistency ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine by me.
I'm also a very big fan of code readability. However, this is also driven by layout and redundancy, for example.
Explicit is good, unless it is really redundant. Redundancy adds clutter. While that is not the case when you write
explicitly defines two variables. The following example is less explicit:
It is clearly a matter of preference or judgement whether or not you would go with the second example. It is certainly nicer on my eyes and I would, therefore, prefer it as long as the righthand side is clearly enough (which is the judgement part) an
Dropping the initialization on the same line will add noise no matter what. Changing
There is a reason why the type of integer literals defaults to
As for
Wouldn't you also have to scroll to the definition and look at the value "where it is nice on the eyes"? Again, believe it or not, I'm not precious about Personally, I now tend to use |
4e4b1b7
to
9b9d891
Compare
Here you go ... I rolled it back and changed |
9b9d891
to
4a27abf
Compare
Travis said it was "unable to fetch some archives". |
Build has been restarted |
@@ -34,12 +36,16 @@ private static string Rename(string name) | |||
return toRename.ContainsKey(name) ? toRename[name] : name; | |||
} | |||
|
|||
public static void DeleteSubdirectories(string parentPath) | |||
public static bool TryDeleteDirectory(string directoryPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this method is no longer used, let's just drop it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
Other than the nitpick above, looks pretty nice to me. Thanks! |
Rename TryDeleteDirectory(string, int, int, int) to DeleteDirectory(...) because this method can still throw exceptions and is not fully in line with the try-parse pattern. Introduce TryDeleteDirectory(string) : bool as a try-parse pattern-compliant option to delete directories recursively without throwing exceptions. Remove DeleteSubdirectories(string) method because it is not used anywhere. Use 'var' keyword consistently across all methods. Related to libgit2#980
4a27abf
to
1a2528f
Compare
Deleted |
Another one in. Thanks! 💖 |
Thanks! |
Rename
TryDeleteDirectory(string, int, int, int)
toDeleteDirectory(string, int, int, int)
because this method can still throw exceptions and is not fully in line with the try-parse pattern.Introduce
TryDeleteDirectory(string) : bool
as a try-parse pattern-compliant option to delete directories recursively without throwing exceptions. It doesn't need an out parameter because the basic method it wraps does not return a value.Remove
DeleteSubdirectories(string)
method because it is not used anywhere (housekeeping).Use
var
keyword consistently across all methods.Related to #980.