Skip to content

Comments

First try#24

Open
alexpol11 wants to merge 2 commits intoiaulitin:masterfrom
alexpol11:master
Open

First try#24
alexpol11 wants to merge 2 commits intoiaulitin:masterfrom
alexpol11:master

Conversation

@alexpol11
Copy link

No description provided.

Александр Полищук added 2 commits July 21, 2020 17:48
private Color color;
private double transparency;
private double fillPercentage;
private double age;
Copy link
Owner

Choose a reason for hiding this comment

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

Мы обычно не выравниваем поля по форматированию. Достаточно поставить пробел между типом и именем поля.

Copy link
Owner

Choose a reason for hiding this comment

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

Вообще есть волшебное сочетание ctrl alt L в idea, которое тебе выровняет весь код в текущем файле. Можно также применять, выбрав пакет - как результат получим форматирование по всем файлам в текущем пакете и вложенных.

this.volume = 0.;
this.color = null;
this.transparency = 0.;
this.fillPercentage = 0.;
Copy link
Owner

Choose a reason for hiding this comment

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

Никогда не видел такой конструкции, сходу не нагуглил. Что она означает?

return this.manufacturer;
}

public void setManufacturer(String mname) {
Copy link
Owner

Choose a reason for hiding this comment

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

Обычно стараются в качестве имени аргумента в сеттере использовать такое же имя, как и у поля.

}

public String getName() {
return this.name;
Copy link
Owner

Choose a reason for hiding this comment

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

В геттерах можно this не использовать


public void setAge(double age) {
this.age = age;
}
Copy link
Owner

Choose a reason for hiding this comment

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

Обычно геттеры-сеттеры идут в начале класса, а остальные методы - после них

return 0.;
this.fillPercentage -= percent;
if (this.fillPercentage < 0.)
{
Copy link
Owner

Choose a reason for hiding this comment

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

Скобочка по-сишному проскочила. Мы ставим на той же строке.

double pouredOut = percent;

if (percent < 0.)
return 0.;
Copy link
Owner

Choose a reason for hiding this comment

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

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

private int rgb;

Color(int r, int g, int b) {
this.rgb = ((r & 0xff) << 16) | ((g & 0xff) << 8) | b & 0xff;
Copy link
Owner

Choose a reason for hiding this comment

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

Обычно без нужды мы не занимаемся разрядными сдвигами, побитовыми операции и тп. Здорово, что ты это знаешь, без шуток, но такие конструкции тяжело читать, а в масштабах работы всего приложения (как правило, большого) выигрыш они дают пшиковый.

this.age = age;
}

Alcohol(String name, String manuf, double degree, double volume) {
Copy link
Owner

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