View
511
Download
0
Embed Size (px)
DESCRIPTION
“Knowing when not to code” is possibly the most important skill of a programmer to learn. In practice, more code is almost always bad: it trashes the CPU cache, hogs the memory bus, uses up more CPU cycles, makes a security audit of the code harder, is harder to follow and maintain, and - last but not least - more code needs more documentation. The art of writing small code is to define a lot, not a LOT.
Citation preview
Art of Writing Small Code
Sumit MisraGeneral Manager
RS Software (India) Limited
Learning by knowledge sharing
Code is developed to address a Problem Space
Problem Space
Learning by knowledge sharing
Code maps the Problem Plane to a Solution Plane
Higher the Solution Plane in abstraction – smaller would the code be
Problem Plane
Solution Plane
Code
Learning by knowledge sharing
Abstraction
Problem Plane
<< G
RAIN
>>
MASHUP CODELARGE GRAIN
ASSEMBLY CODESMALL GRAIN
CODE
ASSEMBLY CODESCRIPTS
Learning by knowledge sharing
Partitioning the Problem space such that the solution planes are
consistent
IS
The prelude to the Art of Writing Small Code
Problem Space
1
3
2
4
Learning by knowledge sharing
Problem Plane
1 2 3 4 1 2 3 4
Large Code Base Small Code Base
Learning by knowledge sharing
Is this the type of small code we want to write ?
World's smallest TETRIS program - one line of BBC BASIC, 256 bytes in all written by Olly Betts
0MODE9:OFF:GCOL-9:CLG:REPEATs=s+VPOS:PRINTCHR$30s:REPEATSYS6,135TOi,p,d:PRINTTAB(p=0)CHR$9;:IFPOS=22VDU3100;VPOS,21;6667;:UNTIL0ELSEUNTILVPOS=25:v=ABSRNDMOD7:VDU31:COLOUR3:REPEATm=9-INKEY(INKEYTRUEOR6)MOD3:FORr=TRUETO1:t=rANDSGNt:IFt=rCOLOURv-15:VDUrEORm:i+=m=7AND9-6*r:IF0ELSEFORn=0TO11:d=nDIV3OR2EORd:VDUd:IF1<<(n+i)MOD12AND&C2590ECDIV8^vAND975t+=POINT(p*POS,31-VPOS<<5):IFrVDUp,8:IF0ELSENEXT,:VDU20:UNTILt*LOGm:UNTILVPOS=3:Z
Learning by knowledge sharing
1960 1970 1980 1990 2000 2010 >>1950
Object Oriented
Internet / Web
Internet / RAD
Distributed / Meta Program / Reflection
Web Programming Language (Dart – Google)Meta Language (Haxe/Neko)
Structured Programs
Abst
racti
onH
igh
Low
Learning by knowledge sharing
Prob
lem
Pla
ne is
Exp
andi
ng Web Services
Web Services
Web Services
Internet
Solution Plane
Learning by knowledge sharing
Internet / Web / Cloud
Smart Mobil
e
GPSGyro-meterMagnetometerPyrometerLight SensorFace DetectorFingerprint Det… more …
Web Services
Mobile Service
User Experience
CODE (HTML5)
LOCATION
APPLICATION
SOC IAL NETWORK
Learning by knowledge sharing
Source: online.wsj.com
Learning by knowledge sharing
Stop Watch program
120 lines
43 lines
25 lines Windows 7 Phone
Java / AWT
Windows / C++
20 lines HTML/Java Script
Use
r Exp
erie
nce
Learning by knowledge sharing
“ I'm sorry for the long letter, my dear, but I did not have time to make it short. “ – Winston Churchill
SMALL CODE would need BETTER DESIGN and GOOD KNOWLEDGE of the available frameworks and services