Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Tuenti - Hardcore PHP - UAM
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Kartones
November 24, 2011
Programming
230
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Tuenti - Hardcore PHP - UAM
@ Universidad Autónoma de Madrid (2011)
Kartones
November 24, 2011
More Decks by Kartones
See All by Kartones
Building Autonomous Agents with gym-retro
kartones
0
54
Python static typing with MyPy
kartones
0
89
High-impact refactors keeping the lights on
kartones
0
76
Remote Work
kartones
0
110
Geospatial CSV Imports Hidden Complexity
kartones
0
62
Intro to GameBoy Development
kartones
0
110
Myths & The Real World of OpenSource Development
kartones
0
54
CartoDB Tech Intro
kartones
0
58
Copy Protection & Cracking History
kartones
0
150
Other Decks in Programming
See All in Programming
属人化した知識を、 AIが辿れる地図にする
pkshadeck
PRO
1
210
リアルな遅延を測る仕様
kota_yata
1
130
実装をデザインガイドラインに追従させるための取り組み / 260731-dip-mosh-design-system
dachi023
0
7.8k
言葉の格闘技のススメ~紙とペンと言葉から始める、キャリアの描き方~
progresscicada
2
180
Webエンジニアなのにブラウザの仕組みがわからないので、Pythonで自作してみた
tatsuki12
4
1.1k
プロポーザルを書いてもらう
pvcresin
0
580
複数の Claude Code が"放置"されてしまう問題をCLI ダッシュボードを自作して解決した話
sumihiro3
1
730
KotlinConf Extended South Korea 2026 Keynote
l2hyunwoo
0
120
仕様書を書く前にハーネスを作る - Agent Native開発は「探索を速く、判定を固く」
gotalab555
4
1.8k
How I Won Prize Money at a Hackathon Using Codex and Symphony Alpha
yasei_no_otoko
0
120
Detecting Compromised CI with eBPF and Cilium Tetragon
lizrice
0
260
仕様駆動開発へのトライを機に チームに適合する手法を模索し続けている話
freee
PRO
0
620
Featured
See All Featured
Reality Check: Gamification 10 Years Later
codingconduct
0
2.3k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
660
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
360
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
420
What's in a price? How to price your products and services
michaelherold
247
13k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
360
The Spectacular Lies of Maps
axbom
PRO
1
940
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
280
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.1k
How to build a perfect <img>
jonoalderson
1
5.9k
Leo the Paperboy
mayatellez
8
2.2k
Transcript
None
None
INTRO • Senior Frontend Engineer @ Tuenti • C#/.NET background,
now a bit of PHP knowledge •
[email protected]
• twitter.com/kartones
AGENDA • The Goal • Shared Hosting to Tuenti-like scale
webs • Typical PHP • PHP Practices • Coding Practices • Web Practices
THE GOAL
THE REAL GOAL Avoid the PHP joke
THE REAL REAL GOAL Build quality PHP code
SHARED HOSTING Internet Frontend + DB
FIRST SPLIT Internet Frontend DB
MORE FRONTENDS Internet Frontends DB
CACHING TIME Internet Frontends DB Cache
MORE CACHING Internet Frontends DB Cache
MASTER/SLAVE DBS Internet Frontends DBs Cache
TUENTI (OVERVIEW) Internet Farm 1 Farm 2 Farm N Others
Frontends Caches DBs
TYPICAL PHP •HTML + PHP script blocks + DB Queries
•If lucky, separated into ¨functions¨ and templates (PHPBB, Wordpress…) •No Object Orientation
TYPICAL PHP News since your last visit: <ul> <? $e
= $_POST['email']; $news = mysql_query("SELECT * FROM news WHERE email='{$e}'"); […] foreach($news as $newsItem) { ?> <li><?=$newsItem[0]?></li> <? } ?> </ul>
TYPICAL PHP News since your last visit: <ul> <? $e
= $_POST['email']; $news = mysql_query("SELECT * FROM news WHERE email='{$e}'"); […] foreach($news as $newsItem) { ?> <li><?=$newsItem[0]?></li> <? } ?> </ul>
TYPICAL PHP News since your last visit: <ul> <? $e
= $_POST['email']; $news = mysql_query("SELECT * FROM news WHERE email='{$e}'"); […] foreach($news as $newsItem) { ?> <li><?=$newsItem[0]?></li> <? } ?> </ul>
TYPICAL PHP News since your last visit: <ul> <? $e
= $_POST['email']; $news = mysql_query("SELECT * FROM news WHERE email='{$e}'"); […] foreach($news as $newsItem) { ?> <li><?=$newsItem[0]?></li> <? } ?> </ul>
TYPICAL PHP function crop_string($string) { if (strlen($string) > 30) {
$string = substr($string, 0, 30) . “…”; } return $string; } $text = crop_string(“developers,developers,developers,developers”);
TYPICAL PHP class StringHelper { const CROP_ELLIPSIS = ‘…’; const
CROP_DEFAULT_SIZE = 30; public static function Crop($text, $cropLength = self::CROP_DEFAULT_SIZE) { if (mb_strlen($text) > $cropLength) { $croppedText = substr($text,0,$cropLength) . Self::CROP_ELLIPSIS; } else { $croppedText = $text; } return $croppedText; } $text = StringHelper::Crop(“developers,developers,developers,developers”);
PHP PRACTICES •PHP 5.3 (or the newest stable version) •Object
Orientation •Namespaces / structured source code tree
PHP PRACTICES •Layered code •MVC is typical and good Controller
Model View
PHP PRACTICES •Breaking loops is ugly for($i = 0; $i
< count($items); $i++) { if ($items[$i] == searchedItem) { break; } }
PHP PRACTICES •Break-free $found = false; for($i = 0; $i
< count($items) && !$found; $i++) { if ($items[$i] == searchedItem) { $found = true; } }
PHP PRACTICES • Try to keep memory usage low •Less
memory, more concurrent PHP processes • unset() • ini_set(“memory_limit”,”8M”);
PHP PRACTICES •Singleton in PHP != Singleton in Java/C#/C++ •Same
PHP execution = same singleton •2 page requests = 2 different singletons •Terribly dangerous in tests •Implement a ¨flushSingleton()¨ static method
PHP PRACTICES •Homogeneous code •Comments •@author tag (Sign your code!)
•Proper variables casing & naming •Good source tree = easy to guess where to find a class •Avoids personal bad practices
PHP PRACTICES • Avoid non testeable objects class Game {
private $player1 = new GamePlayer(); private $player2 = new GamePlayer(); public function Play() { // Logic that uses $player1 & $player2 } }
PHP PRACTICES • Create testeable objects class Game { private
$player1 = null; private $player2 = null; public function __construct(IGameEntity $playerA, IGameEntity $playerB) { $this->player1 = $playerA; $this->player2 = $playerB; } public function Play() { // Logic that uses $player1 & $player2 } }
PHP PRACTICES • Defensive Programming • defined() • isset() •
class_exists() • method_exists()
CODING PRACTICES Learn & use Source Code Control •Distributed •Best
options: SVN,Git, Mercurial •Always linked to a ticket control system •Learn to branch, diff, merge, resolve conflicts •Hard at first, pays off in big projects
CODING PRACTICES Learn & do Testing •Unit tests •Test DB
data (Fixtures) •Mock Objects •Integration tests •Acceptance tests
WEB PRACTICES •Learn Kung-fu: •HTTP protocol basics •Some Javascript •Minimal
CSS •Robots.txt •Favicon.ico •Sitemap.xml •Cookies •Encoding •Web Security basics
WEB PRACTICES •Minimize HTML, CSS, JS •Google closure Compiler •YuiCompressor
•Firebug •Use tools to detect improvements: •PageSpeed (Firefox/Chrome) •YSlow (Firefox) •MySpace Performance Tracker (IE)
WEB PRACTICES •Use the client to store data •Cookies (4KB
max) •LocalStorage (HTML5) •Global scoped Javascript variables (AJAX only) •Javascript Datasources (Tuenti AJAX)
WEB PRACTICES •If you don’t need realtime, be lazy •Lazy
loading •Lazy deletion •Job queues instead of realtime operations
THE END ¿Questions? http://dev.tuenti.com http://jobs.tuenti.com