Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Laracon Online 2020 - Refactoring to Simplicity
Search
Marcel Pociot
August 26, 2020
Programming
980
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Laracon Online 2020 - Refactoring to Simplicity
Marcel Pociot
August 26, 2020
More Decks by Marcel Pociot
See All by Marcel Pociot
BotMan - From Zero to Chatbot [Laravel Live]
mpociot
1
310
Other Decks in Programming
See All in Programming
大喜利で理解するLLM as a Judge / Understanding LLM-as-a-Judge through Ogiri
rockname
0
160
仕様駆動開発による爆速プロダクト開発 / Bakusoku Spec Driven Development
kobakei
0
130
『寄り添うラジオ』をAIで作る 体験価値から逆算した、会話しないUXと品質設計
theoriatec2024
3
190
スマート反転とウェブアクセシビリティ
camiha
0
210
速く作れる。その次は、速く確かめられる開発へ 〜AIネイティブ開発を支える、Shift Down〜 / Can build fast. Next, moving to development where we can verify fast.
rkaga
6
4.7k
速習iPhone Duo対応
yuukiw00w
2
780
WebMCP Challenge に星空観察アプリで参加した話
okajun35
0
190
SONY CISC-NEWS NWS-1750 + NWB-225 フレームバッファの NetBSD/news68k ドライバ実装 / OSC2026Hiroshima
tsutsui
0
150
iOSDC2026登壇資料.pdf
riofujimon
0
190
【高い買い物LT会】初任給で話題の国産フィジカルAIを買った話
akagami
PRO
0
170
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
5k
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
2.9k
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
41
2.7k
Scaling GitHub
holman
464
140k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
250
Joys of Absence: A Defence of Solitary Play
codingconduct
1
530
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6.2k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
RailsConf 2023
tenderlove
30
1.6k
Design in an AI World
tapps
1
330
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
920
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
How STYLIGHT went responsive
nonsquared
100
6.3k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
830
Transcript
REFACTORING TO SIMPLICITY
MARCEL POCIOT BEYOND CODE @MARCELPOCIOT
WHAT DOES "SIMPLE" MEAN?
<?php use PHPUnit\Framework\TestCase; class StackTest extends TestCase { public function
testPushAndPop() { $stack = []; $this->assertSame(0, count($stack)); array_push($stack, 'foo'); $this->assertSame('foo', $stack[count($stack)-1]); $this->assertSame(1, count($stack)); $this->assertSame('foo', array_pop($stack)); $this->assertSame(0, count($stack)); } }
public function test_profile_photo_can_be_updated() { $file = new UploadedFile( public_path('img/color-logo.png'), 'color-logo.png',
'image/png', null, null, true ); Storage::shouldReceive('disk') ->once() ->with('public') ->andReturn($disk = Mockery::mock('StdClass')); $disk->shouldReceive('put'); $disk->shouldReceive('url')->once()->andReturn('/profile/photo'); $this->actingAs(factory(User::class)->create()) ->json('POST', '/settings/photo', [ 'photo' => $file, ]); $this->seeStatusCode(200); $this->seeInDatabase('users', [ 'photo_url' => '/profile/photo', ]); }
WHEN WE TEACH, WE START SIMPLE ▸ Focus on what
you want to teach ▸ Let the learner focus on one thing at a time ▸ ... it fits on a slide?
REALITY KICKS IN Real-life projects are not simple
DEVELOPERS LOVE COMPLEXITY
I'm not a begi er! I write my own framework!
— Every developer, at some point
L k at these 1000 LOC that I wrote. Only
I can understand it! — Senior Software Developer
None
None
None
SIMPLE CODE IS... ▸ Expressive ▸ Readable ▸ Understandable ▸
Self explanatory ▸ Reassuring ▸ Fun
IS SIMPLE CODE BETTER?
Yes
Thank you for coming to my TED talk
IS SIMPLE CODE FASTER TO WRITE?
Nope
None
None
None
TINKERWELL
FAMILIAR CODE != SIMPLE CODE
IS SIMPLER CODE BETTER TO TEST?
Usua y, Yes
class MetricController extends Controller { /** * List the metrics
for the given resource. * * @param \Laravel\Nova\Http\Requests\MetricRequest $request * @return \Illuminate\Http\Response */ public function index(MetricRequest $request) { return $request->availableMetrics(); } }
OKAY...SIMPLE IS GOOD AND ALL, BUT WHAT'S IN FOR ME?
▸ Simpler code is more readable ▸ Unsurprising code is
more maintainable ▸ Expressive code is fun !
HOW CAN I WRITE SIMPLE CODE?
KNOW WHAT SIMPLE CODE LOOKS LIKE
READ OTHER PEOPLES CODE
DO CODE REVIEWS
REFACTOR CODE AS IT GROWS
SIMPLE RULES FOR SIMPLER CODE
NAMING VARIABLES $list = MapSpot::orderBy("name")->get(); foreach($list as $key => $row)
{ $max = MapSpotSight::where("map_spot_id", "=", $row->id)->max("datetime"); $list[$key]->sights = MapSpotSight::where("map_spot_id", "=", $row->id) ->where("hides_at", ">", time()) ->where("datetime", "=", $max) ->orderBy("hides_at", "ASC") ->get(); }
USEFUL METHOD NAMES public function updateData($user, $project) { // ...
}
RETURN EARLY public function doSomething($someParameter, $someOtherParameter) { if ($someParameter ===
1) { if ($someOtherParameter === 1) { // do the actual work } } }
RETURN EARLY public function doSomething($someParameter, $someOtherParameter) { if ($someParameter !==
1) { return; } if ($someOtherParameter !== 1) { return; } // do the actual work }
Any inte igent f l can make things bi er,
more complex, and more violent. It takes a touch of genius—and a lot of courage to move in the opposite direction. — Albert Einstein
Any inte igent f l can make things bi er,
more complex, and more violent. It takes a touch of genius—and a lot of courage to move in the opposite direction. — E.F. Schumacher
SIMPLICITY TAKES COURAGE
None
None
SPEAKING OF LARAVEL
Route::get('user/(:num)', function($id) { // });
if (Auth::check()) { return "You're logged in!"; }
test('asserts true is true', function () { assertTrue(true); });
class SearchUsers extends Component { public $search = ''; public
function render() { return view('livewire.search-users', [ 'users' => User::where('username', $this->search)->get(), ]); } }
TAKE COURAGE ▸ Know what you can skip to make
things easy and simple ▸ Be brave enough to present your code ▸ Leave behind code that reflects you and your abilities
Now that my code is expressive, can I be replaced?
▸ Learn ▸ Read ▸ Care ▸ Test ▸ Communicate
None
Writing simple code is not simple But worth it
THANK YOU