Hot answers tagged

5

Stylistically, the for loop is more readable. As a general rule, if you start the loop at 1, then I would prefer the termination condition to use <=; if you start counting from 0, then < would be better. The design of this function is conceptually flawed. It will return an unused filename, but presumably you will eventually want to create a file ...


5

First, I'm afraid all the path handling and validation is a common anti-pattern of trying to check every conceivable error condition before trying to do something, in order to avoid lots of error-handling code. The problem is it doesn't work - it is literally impossible to guard against all possible errors, because an error may be introduced after you verify ...


3

Unfortunately I don't have time to finish my answer right now, but here's what I think so far: Main.java If your whole program is built around reading and manipulating a single file, it's customary and useful to take the name of that file in as a parameter (i.e. read it from args) instead of hardcoding it. (In future versions you might replace the filename ...


2

Personally I'm a fan of using Regex when it comes to parsing strings for the simplicity it provides. This way we can check for the next available file name without relying on loops. Only problem I see with this method is if the directory contains an absurd amount of files. //the following regex pattern divides the filename into 3 groups: // [1] directory + ...


1

require style I (and most of the Node developers I've worked with) prefer the style where require is put on top. As stated in the guide you linked, it gives a clearer overview of what are dependencies of the module/file you're writing. No one likes to see that if some condition is successful, then a new module will be loaded. It's just unnatural. On the ...


1

Simple approach, with openpyxl import openpyxl current_wb = openpyxl.load_workbook('./data/items.xlsx') current_sheet = current_wb.get_active_sheet() new_wb = openpyxl.Workbook() new_sheet = new_wb.get_active_sheet() for row in range(1, current_sheet.max_row + 1): for col in range(1, current_sheet.max_column + 1): new_sheet.cell(col, row).value = ...


1

It appears that the string you pass into the method is a type of picture not really a filename, since the filename needs an index attached. I'm not a big fan of either approach. I think using GetFiles and using the Length property is easier to see what's happening. Something like this should work: using System; using System.IO; private static string ...


1

I think this bit is worth refactoring: public void printOptions(){ System.out.println("Options:"); System.out.println("0. Quit"); System.out.println("1. Add a new dog"); System.out.println("2. Add a new cat"); System.out.println("3. Print all animals"); System.out.println("4. Delete an animal"); ...


1

Animal.java I do not know which version of Java you are using, but consider version 8 as it is pretty much the industry standard now and use LocalDate instead of Date species seems like it should be an Enum, not a String InputValidator.java Keep your scopes to smallest possible, why is Scanner an instance field? Do not forget to close your Scanner public ...


1

OOP considerations: Dog and Cat are both animals; You should have Dog and Cat classes which extend Animal. You have basically three concerns (business logic) in your application: (1) Get input from command line, (2) Validate inputs and translate inputs to entity, (3) Apply CRUD operations to perform on entities. You can create one interface for each ...


Only top voted, non community-wiki answers of a minimum length are eligible