Skip to content
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

Зубков Андрей #164

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

HardreaM
Copy link

@HardreaM HardreaM commented Feb 3, 2024

var text = document.GetText();

return text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Skip(1);
}

public IList<string> GetAvailableExtensions() => new List<string>() { "doc", "docx" };
private bool FileExists(string inputPath, out string error)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

С out параметрами нужно быть осторожным, они не являются панацеей. out параметры нельзя использовать, если метод асинхронный, компилятор не даст даже написать такой метод, а асинхронного кода в продакшне будет предостаточно. Если есть хоть небольшой намек на то, что метод может стать асинхронным, лучше сразу перейти на использование других подходов.

Тут, например, можно было использовать все тот же паттерн Result

}

public IList<string> GetAvailableExtensions()
private bool FileExists(string inputPath, out string error)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хм, точно такой же метод находится в классе DocReader, один-в-один, давай вынесем в отдельный статический класс-утилиту и заиспользуем в двух местах

throw new ArgumentException($"{generatorName} layouter is not supported");
return registeredGenerators.ContainsKey(generatorName)
? Result.Ok(registeredGenerators[generatorName])
: Result.Fail<IPointGenerator>($"{generatorName} layouter is not supported");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут было бы прикольно ещё дать пользователю сразу подсказку, а какие тогда поддерживаются?

if (!palette.IsSuccess)
return Result.Fail<Bitmap>(palette.Error);

var layouter = new CloudLayouter(pointGenerator.Value);
var tags = PlaceWords(words, layouter);

return !ValidateImageBorders(tags)
? Result.Fail<Bitmap>(
$"Tags don't fit to given image size of {appSettings.CloudWidth}x{appSettings.CloudHeight}")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Аналогичный момент, а что нужно сделать пользователю, чтобы это исправить? Уменьшить / увеличить размеры? Может быть сразу подсказать, какой размер изображения получился сейчас?

{
return palettes.ContainsKey(paletteName)
? Result.Ok(palettes[paletteName])
: Result.Fail<IPalette>($"Palette with name {paletteName} doesn't exist");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А какие палетки можно использовать? Этот текст ошибки не дает ответ на этот вопрос

var extension = inputPath.Split(".").Last();
return readers.ContainsKey(extension)
? Result.Ok(readers[extension])
: Result.Fail<IFileReader>($"Reading of file {inputPath} with extension {extension} is not supported");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я думаю принцип ты понял)

{
public IEnumerable<(string word, int rank)> RankWords(IEnumerable<string> words)
{
return words.GroupBy(word => word.Trim().ToLowerInvariant()).OrderByDescending(g => g.Count()).ToList()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А зачем Ranker триммит и приводит к нижнему регистру слова, если это уже сделал (или должен был сделать) препроцессор? Если оно должно существовать здесь, то не очень понятна ответственность препроцессора, зачем он нужен в принципе

return settings.Value;
}

public static ContainerBuilder ConfigureBuilder(IAppSettings settings)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сейчас все сервисы регистрируются по умолчанию в скоупе InstancePerDependency, это значит что при каждом запросе сервиса будет создаваться его экземпляр, даже если у него нет состояния. С таким подходом и увеличением количества сервисов можем начать проигрывать в памяти и скорости выполнения запросов, так как перед выполнением запроса нужно будет создать все зависимости заново.

Предлагаю чуть пооптимизировать и попробовать некоторые зависимости перевести в другие скоупы, в том числе синглтон

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants