art of writing small code by sumit misra
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.TRANSCRIPT
![Page 1: Art of Writing Small Code by Sumit misra](https://reader036.vdocuments.us/reader036/viewer/2022062405/5564432ed8b42ace308b5893/html5/thumbnails/1.jpg)
Art of Writing Small Code
Sumit MisraGeneral Manager
RS Software (India) Limited
![Page 2: Art of Writing Small Code by Sumit misra](https://reader036.vdocuments.us/reader036/viewer/2022062405/5564432ed8b42ace308b5893/html5/thumbnails/2.jpg)
Learning by knowledge sharing
Code is developed to address a Problem Space
Problem Space
![Page 3: Art of Writing Small Code by Sumit misra](https://reader036.vdocuments.us/reader036/viewer/2022062405/5564432ed8b42ace308b5893/html5/thumbnails/3.jpg)
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
![Page 4: Art of Writing Small Code by Sumit misra](https://reader036.vdocuments.us/reader036/viewer/2022062405/5564432ed8b42ace308b5893/html5/thumbnails/4.jpg)
Learning by knowledge sharing
Abstraction
Problem Plane
<< G
RAIN
>>
MASHUP CODELARGE GRAIN
ASSEMBLY CODESMALL GRAIN
CODE
ASSEMBLY CODESCRIPTS
![Page 5: Art of Writing Small Code by Sumit misra](https://reader036.vdocuments.us/reader036/viewer/2022062405/5564432ed8b42ace308b5893/html5/thumbnails/5.jpg)
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
![Page 6: Art of Writing Small Code by Sumit misra](https://reader036.vdocuments.us/reader036/viewer/2022062405/5564432ed8b42ace308b5893/html5/thumbnails/6.jpg)
Learning by knowledge sharing
Problem Plane
1 2 3 4 1 2 3 4
Large Code Base Small Code Base
![Page 7: Art of Writing Small Code by Sumit misra](https://reader036.vdocuments.us/reader036/viewer/2022062405/5564432ed8b42ace308b5893/html5/thumbnails/7.jpg)
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
![Page 8: Art of Writing Small Code by Sumit misra](https://reader036.vdocuments.us/reader036/viewer/2022062405/5564432ed8b42ace308b5893/html5/thumbnails/8.jpg)
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
![Page 9: Art of Writing Small Code by Sumit misra](https://reader036.vdocuments.us/reader036/viewer/2022062405/5564432ed8b42ace308b5893/html5/thumbnails/9.jpg)
Learning by knowledge sharing
Prob
lem
Pla
ne is
Exp
andi
ng Web Services
Web Services
Web Services
Internet
Solution Plane
![Page 10: Art of Writing Small Code by Sumit misra](https://reader036.vdocuments.us/reader036/viewer/2022062405/5564432ed8b42ace308b5893/html5/thumbnails/10.jpg)
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
![Page 11: Art of Writing Small Code by Sumit misra](https://reader036.vdocuments.us/reader036/viewer/2022062405/5564432ed8b42ace308b5893/html5/thumbnails/11.jpg)
Learning by knowledge sharing
Source: online.wsj.com
![Page 12: Art of Writing Small Code by Sumit misra](https://reader036.vdocuments.us/reader036/viewer/2022062405/5564432ed8b42ace308b5893/html5/thumbnails/12.jpg)
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
![Page 13: Art of Writing Small Code by Sumit misra](https://reader036.vdocuments.us/reader036/viewer/2022062405/5564432ed8b42ace308b5893/html5/thumbnails/13.jpg)
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