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
Good Code
Search
barisdemiroz
November 21, 2013
Programming
3
140
Good Code
The presentation I made for software engineering course @{Bogazici University}
barisdemiroz
November 21, 2013
Tweet
Share
Other Decks in Programming
See All in Programming
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
デザインパターンで理解するLLMエージェントの作り方 / How to develop an LLM agent using agentic design patterns
rkaga
3
390
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
Modular Monolith Monorepo ~シンプルさを保ちながらmonorepoのメリットを最大化する~
yuisakamoto
5
350
Amazon Qを使ってIaCを触ろう!
maruto
0
420
Jakarta EE meets AI
ivargrimstad
0
740
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
110
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.2k
as(型アサーション)を書く前にできること
marokanatani
10
2.7k
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
480
Featured
See All Featured
GraphQLとの向き合い方2022年版
quramy
43
13k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
A Tale of Four Properties
chriscoyier
156
23k
The Cult of Friendly URLs
andyhume
78
6k
Building Applications with DynamoDB
mza
90
6.1k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Optimizing for Happiness
mojombo
376
70k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
Facilitating Awesome Meetings
lara
50
6.1k
Building Adaptive Systems
keathley
38
2.3k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Transcript
Barış Evrim Demiröz software engineering @boun 21.11.2013
None
None
None
None
// increments i by one i++;
itemCount++;
None
None
• Function/Variable naming • Code style – Java conventions (Eclipse
CTRL+ALT+F) – Google conventions coming soon!
None
x = a*b;
salary = hoursWorked*rate;
None
*:execute perform do carry fulfill accomplish
None
None
None
None
None
if (items.size() < 30)
if (items.size() < MAX_ITEMS_ALLOWED)
None
line.split(",");
line.split(DELIMITER);
line.split(DELIMITER);
None
None
None
None
None
None
None
None
• Should be simple • Should be fast
private void testNoCookie( Cookie[] cookies ) { when( request.getCookies() ).thenReturn(
cookies ); CookieHandler handler = new CookieHandler( request ); assertFalse( handler.hasCookie() ); handler.createOrRenew( response ); assertTrue( handler.hasCookie() ); assertTrue( handler.getUUID().length() > 0 ); }
@Test public void testNoCookie1() { testNoCookie( null ); } @Test
public void testNoCookie2() { testNoCookie( new Cookie[] {} ); }
None
public void testAdd() { assertEquals(3, calculator.add(2, 1)); assertEquals(2, calculator.add(2, 0));
assertEquals(1, calculator.add(2, -1)); }
public class Calculator { public int add(int a, int b)
{ return a + b; } }
public class Calculator { private AdderFactory adderFactory; public Calculator(AdderFactor adderFactory)
{ this.adderFactory = adderFactory; } public int add(int a, int b) { Adder adder = adderFactory.createAdder(); ReturnValue returnValue = adder.compute(new Number(a), new Number(b)); return returnValue.convertToInteger(); } }
SO • others • blogs • twitter
None
None
None
None
1
None
None
double calculate(Context foo) { checkNotNull(foo); // rest of the computation…
}
None
None
List<Integer> numbers = asList(1, 2, 3, 4, 5, 6); numbers.forEach(System.out::println);
sumAll(numbers, n -> n % 2 == 0);
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
double calculate(int foo) { if (foo < 0) return 0;
// rest of the computation… }
You Ain’t Gonna Need It
None
None
None
None
None
None
public class LongDivision { private static final long MILLIS_PER_DAY =
24 * 60 * 60 * 1000; private static final long MICROS_PER_DAY = 24 * 60 * 60 * 1000 * 1000; public static void main(String[] args) { System.out.println(MICROS_PER_DAY / MILLIS_PER_DAY); } }
public class LongDivision { private static final long MILLIS_PER_DAY =
24 * 60 * 60 * 1000; private static final long MICROS_PER_DAY = 24 * 60 * 60 * 1000 * 1000; public static void main(String[] args) { System.out.println(MICROS_PER_DAY / MILLIS_PER_DAY); } }
public class LongDivision { private static final long MILLIS_PER_DAY =
24 * 60 * 60 * 1000; private static final long MICROS_PER_DAY = 24 * 60 * 60 * 1000 * 1000; public static void main(String[] args) { System.out.println(MICROS_PER_DAY / MILLIS_PER_DAY); } } overflows
public class LongDivision { private static final long MILLIS_PER_DAY =
24L * 60 * 60 * 1000; private static final long MICROS_PER_DAY = 24L * 60 * 60 * 1000 * 1000; public static void main(String[] args) { System.out.println(MICROS_PER_DAY / MILLIS_PER_DAY); } }
None
Don’t hold all the complexity in your mind
None
None
None
None