laravel-kata
laravel-kata copied to clipboard
The greatest collection of the worst code
Laravel Kata
The greatest collection of the worst code.
Concepts
- Practice the fundamentals
- Expose common mistakes
- Lab to theorycraft mechanics
Dependencies
- Docker
- Composer
- NPM
Getting started
npm i
npm run restart
./vendor/bin/sail kata:run
Sample challenge
Calculate the value of pi.
Solution A
namespace App\Challenges\A;
class Sample
{
public function calculatePi(): float
{
$denominator = 1;
$sum = 0;
for ($i = 0; $i < 100000; $i++) {
$sum = ($i % 2 === 0)
? $sum + (4 / $denominator)
: $sum - (4 / $denominator);
$denominator += 2;
}
return $this->return(round($sum, 2));
}
}
Solution B
namespace App\Challenges\B;
class Sample
{
public function calculatePi(): float
{
return $this->return(round(M_PI, 2));
}
}
Report
What are katas?
Katas are code challenges focused on improving skill and technique. Some train programming fundamentals, while others focus on complex problem solving. Some are puzzles meant to test your creative problem solving, while others are based on real world coding scenarios.
The term was first coined by Dave Thomas, co-author of the book The Pragmatic Programmer as an acknowledgment to the Japanese concept of kata in the martial arts. Dave's version of the concept defines a code kata as an exercise in programming which helps a programmer sharpen their skills through practice and repetition. - Codewars