Clean Code Development Best Practices Quiz
39 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is one of the hints for development mentioned in the text?

  • Commit debug code for production use
  • Avoid writing code in English
  • Use PHP native functions without any modification
  • Write short methods (correct)

Why should developers write code in English according to the text?

  • To confuse other developers
  • To restrict the readability of the code
  • To enable developers who don't speak the same language to understand it (correct)
  • To make the code more difficult to maintain

What is one of the reasons mentioned in the text for not committing debug code?

  • Debug code ensures error-free code
  • Debug code helps in production deployment
  • Debug code should be added for better readability
  • Debug code is unnecessary in a production codebase (correct)

Why is committing commented out code discouraged according to the text?

<p>Commented out code can be retrieved from previous commits (B)</p> Signup and view all the answers

What do quality tools help with according to the text?

<p>Spotting issues in code quality (B)</p> Signup and view all the answers

What practice significantly aids in producing clean code according to the text?

<p>Writing clean and readable code in English (D)</p> Signup and view all the answers

What is the main purpose of a repository in general?

<p>Handling data source operations (A)</p> Signup and view all the answers

What should a method name reflect?

<p>The single functionality of the method (B)</p> Signup and view all the answers

In the context of the InvoiceSimulationService, why is it not considered a 'Helper'?

<p>It contains methods specific to the Livewire component InvoiceSimulation (B)</p> Signup and view all the answers

What does the text recommend if a method performs multiple tasks?

<p>Dividing the method into multiple smaller methods (D)</p> Signup and view all the answers

If you have a Team Model, what type of repository are you likely to create?

<p>TeamRepository (C)</p> Signup and view all the answers

When should you put the SQL query in a Data Object Accessor according to the text?

<p>Only if Eloquent methods are not sufficient (B)</p> Signup and view all the answers

What is the suggested maximum number of lines for a method body according to Martin?

<p>4 lines (D)</p> Signup and view all the answers

How can you reduce the length of a method that exceeds 15/20 lines?

<p>Group lines that make sense together into another private method (A)</p> Signup and view all the answers

What does SRP stand for in the context of 'Clean code'?

<p>Single Responsability Principle (C)</p> Signup and view all the answers

According to Martin, what is the problem with classes like 'LetterManager'?

<p>They do everything letter-related (D)</p> Signup and view all the answers

What suggestion does Martin give when naming classes for specific responsibilities?

<p>Create a class even if it's to write only one method in it (D)</p> Signup and view all the answers

How can you improve the readability of your code according to Martin?

<p>Group related lines into private methods with clear names (C)</p> Signup and view all the answers

What is the exception for rearranging code in PHP for Models files?

<p>Leave methods starting with registerMediaConversions first (D)</p> Signup and view all the answers

Why has the scalingo build image limit been increased from 1GB to 3GB?

<p>To accommodate the installation of Chromium for Browsershot (B)</p> Signup and view all the answers

Where should Browsershot be run according to the provided information?

<p>On async workers (A)</p> Signup and view all the answers

When should you rearrange your code in PHP according to the provided settings?

<p>Only when you submit a PR for review (B)</p> Signup and view all the answers

Why should you add a backslash to PHP native functions?

<p>To improve app performance by reducing execution time (D)</p> Signup and view all the answers

What is the minimum memory requirement to run a worker based on the text?

<p>512MB (A)</p> Signup and view all the answers

In what PHPStorm settings section should you go to auto-format your code?

<p>Editor &gt; Code Style &gt; PHP (A)</p> Signup and view all the answers

Why is running Telescope on staging or production discouraged?

<p>To avoid memory leaks and prevent dynos from crashing (D)</p> Signup and view all the answers

Why can integrating the php-cs-fixer rule permanently be a challenge?

<p>It necessitates setting the option --allow-risky.yes (B)</p> Signup and view all the answers

What action should you take in PHPStorm to reformat your code after importing a file?

<p>Go to Menu &gt; Code &gt; Reformat Code (A)</p> Signup and view all the answers

What is the main reason behind adding a backslash to PHP native functions according to the provided text?

<p>To avoid namespace conflicts (C)</p> Signup and view all the answers

Why does the author recommend using infinitive verbs on buttons on the interface?

<p>To depersonalize the interface and involve the user less (D)</p> Signup and view all the answers

Why does the author mention that 'vous' is used minimally in the interface?

<p>To avoid personal commitment from the user (A)</p> Signup and view all the answers

What is the main reason behind using 'vous' sparingly in the interface according to the text?

<p>To minimize user involvement and personal commitment (A)</p> Signup and view all the answers

How does using infinitive verbs on buttons contribute to achieving the depersonalization goal in the interface?

<p>By keeping user involvement to a minimum level (C)</p> Signup and view all the answers

Why does the author emphasize avoiding personal commitment from users on the platform?

<p>To align with a specific branding strategy (B)</p> Signup and view all the answers

Why does the text recommend using infinitive verbs on buttons or call to action links?

<p>To minimize user involvement (B)</p> Signup and view all the answers

Why is 'vous' used sparingly in the interface according to the text?

<p>To avoid personal commitment from users (A)</p> Signup and view all the answers

What is the primary reason for depersonalizing the interface and minimizing personal commitment from users?

<p>To treat the SirEnergies account primarily as a tool (C)</p> Signup and view all the answers

How does using depersonalized verbs in the infinitive form affect user interaction?

<p>It minimizes user involvement (D)</p> Signup and view all the answers

What is the rationale behind avoiding personal commitment from users while interacting with the SirEnergies account?

<p>To maintain focus on the account as a tool (A)</p> Signup and view all the answers

Study Notes

Browsershot

  • Browsershot is used as a wrapper for Chromium.
  • The Scalingo build image limit has been increased from 1GB to 3GB due to the installation of Chromium.
  • Browsershot should not be run on web dynos, but instead on async workers, which have 192MB of RAM.
  • To run Browsershot, a job must specify the queue 'browser' and workers must have a minimum of 512MB of RAM.

PHPStorm Settings

  • Use the settings file 'PHPStorm - SirEnergies - 20230209.xml' to auto-format code in PHPStorm.
  • Steps to import settings: go to Settings, then Editor > Code Style > PHP, click on the wheel, then Import, and select the file.

Archives

  • Use the settings file 'PHPStorm - Project - 20220926.xml' to auto-format code in PHPStorm.

Clean Code

  • Method bodies should be no more than 4 lines long, but 15 to 20 lines is a more reachable goal.
  • Reduce long methods by grouping lines into private methods with understandable names.
  • A method or class should have only one responsibility (SRP - Single Responsibility Principle).
  • Classes should be named according to their responsibility, such as 'LetterSender' or 'LetterDownloader'.

Development

  • Write code in English.
  • Do not commit commented out code or debug code.
  • Write short methods.
  • A method or class should do one thing (SRP).
  • Rearrange code according to the given settings.
  • Add backslashes to PHP native functions.

Telescope

  • Do not run Telescope on staging or production, as it has memory leaks and can cause dynos to crash.
  • Enable Telescope only for debugging, and disable it immediately after.

Development Owner

  • Owner: Chloé Briquet
  • Tags: Clean code, Write your code in English, Do not commit commented out code, Do not commit debug code, Write short methods, Your method/class should do one thing (SRP)

Repositories

  • A repository is responsible for handling data source operations.
  • A repository provides a centralized way of managing database-related operations and increases code readability.
  • If you have a 'Team' model, you'll likely have a 'TeamRepository'.
  • All public methods of a repository should only use Eloquent methods to access data.

Action or Service?

  • The repository provides a centralized way of managing database-related operations.
  • If you need to write SQL, put the query in a Data Object Accessor.

Wording

  • Use 'vous' with users but as little as possible.
  • Use the infinitive on buttons or call to action links with only a word or noun group.
  • This tone is used to depersonalize the interface and not engage users in actions.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

Code Dev 1.pdf
Code Dev 2.pdf

Description

Test your knowledge on clean code development practices and best practices for writing maintainable code. Topics include writing short methods, single responsibility principle (SRP), avoiding commented out or debug code, and choosing between repositories, actions, or services.

More Like This

Refactoring and Clean Code
10 questions

Refactoring and Clean Code

IntuitiveMistletoe avatar
IntuitiveMistletoe
Princípios de Clean Code y SOLID
37 questions

Princípios de Clean Code y SOLID

InvaluableMoldavite2150 avatar
InvaluableMoldavite2150
Use Quizgecko on...
Browser
Browser