osiegmar / FastCSV

CSV library for Java that is fast, RFC-compliant and dependency-free.
https://fastcsv.org/
MIT License
551 stars 93 forks source link

Class naming disambiguation #23

Closed charphi closed 3 years ago

charphi commented 6 years ago

In the current version, some class names are not clear (see https://github.com/osiegmar/FastCSV/issues/7#issuecomment-368565601). Here are some suggestions for 2.x:

Solution 1: reader, writer, fluent factories

old name new name
CsvReader CsvReaderFactory
CsvParser CsvReader
CsvWriter CsvWriterFactory
CsvAppender CsvWriter
CsvWriterFactory factory = new CsvWriterFactory().fieldSeparator(';');

try(StringWriter writer = new StringWriter()) {
  try(CsvWriter csv = factory.create(writer)) {
    ...
  }
}

Path file = ...;
try(CsvWriter csv = factory.create(file, StandardCharsets.UTF_8)) {
  ...
}

Solution 2: reader, writer, bean settings

old name new name
CsvReader CsvReaderSettings
CsvParser CsvReader
CsvWriter CsvWriterSettings
CsvAppender CsvWriter
CsvWriterSettings settings = new CsvWriterSettings();
settings.setFieldSeparator(';');

try(StringWriter writer = new StringWriter()) {
  try(CsvWriter csv = CsvWriter.create(settings, writer)) {
    ...
  }
}

Path file = ...;
try(CsvWriter csv = CsvWriter.create(settings, file, StandardCharsets.UTF_8)) {
  ...
}

Solution 3: reader, writer, value settings

old name new name
CsvReader CsvReaderSettings
CsvParser CsvReader
CsvWriter CsvWriterSettings
CsvAppender CsvWriter
CsvWriterSettings settings = CsvWriterSettings.builder().fieldSeparator(';').buid();

try(StringWriter writer = new StringWriter()) {
  try(CsvWriter csv = CsvWriter.create(settings, writer)) {
    ...
  }
}

Path file = ...;
try(CsvWriter csv = CsvWriter.create(settings, file, StandardCharsets.UTF_8)) {
  ...
}
ispringer commented 5 years ago

I don't mind the class names that much, but I do agree CsvReader and CsvWriter should have fluent builders. It makes configuring them easier and less verbose, and allows instances to be immutable. For example:

CsvReader csvReader = CsvReader.builder()
    .fieldSeparator(';')
    .textDelimiter('\'')
    .build()
osiegmar commented 4 years ago

Will be handled in 2.0 - see https://github.com/osiegmar/FastCSV/blob/version2-rewrite/README.md