Skip to content

first commit#1

Open
lisvasya wants to merge 1 commit intomainfrom
first-iteration
Open

first commit#1
lisvasya wants to merge 1 commit intomainfrom
first-iteration

Conversation

@lisvasya
Copy link
Owner

@lisvasya lisvasya commented Apr 1, 2025

No description provided.

Copy link

@ivannizh ivannizh left a comment

Choose a reason for hiding this comment

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

Василиса, привет!

Отлично получилось поработать со структурами и интерфейсами, работа принята!

...
func (ds *DaySteps) Parse(datastring string) (err error) {
parts := strings.Split(datastring, ",")
if len(parts) == 2 {
Copy link

Choose a reason for hiding this comment

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

Большой блок IF и маленький else - плохо!
Можно просто инвертировать условие, чтобы был маленький IF с выходом из функции
image

if len(parts) == 2 {
num, err := strconv.Atoi(parts[0])
if err != nil {
return errors.New("ошибка конвертации строки в int")
Copy link

Choose a reason for hiding this comment

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

  1. Теряешь сообщение об ошибки
  2. Ошибку лучше писать на английском
Suggested change
return errors.New("ошибка конвертации строки в int")
return fmt.Errorf("conversion error: %w", err)

// создайте метод ActionInfo()
...
func (ds DaySteps) ActionInfo() (string, error) {
if ds.Duration <= 0 {
Copy link

Choose a reason for hiding this comment

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

Тут нигде не используется в расчетах, так что можно опустить

dist := spentenergy.Distance(ds.Steps)
cal, err := spentenergy.WalkingSpentCalories(ds.Steps, ds.Weight, ds.Height, ds.Duration)
if err != nil {
return "", errors.New("ошибка подсчета каллорий")
Copy link

Choose a reason for hiding this comment

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

Suggested change
return "", errors.New("ошибка подсчета каллорий")
return "", fmt.Errorf("error in WalkingSpentCalories: %w", err)

var dur time.Duration
var act string
slice := strings.Split(datastring, ",")
if len(slice) == 3 {
Copy link

Choose a reason for hiding this comment

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

Аналогично нужно инвертировать условие

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