SlideShare une entreprise Scribd logo
1  sur  42
Télécharger pour lire hors ligne
Don’t Reinvent
The Wheel
Kenju Wagatsuma
Agenda: ->
❖ 1m : Introduction
❖ 3m : Main part
❖ 1m : Conclusion
/**
* Introduce Myself
*
* @kenjuwagatsuma
*/
'me' = {
name : 'Kenju Wagatsuma ( KJ )’,
}
'me' = {
name : 'Kenju Wagatsuma ( KJ )’,
company : 'Recruit Technologies Co.,LTD.',
}
'me' = {
name : 'Kenju Wagatsuma ( KJ )’,
company : 'Recruit Technologies Co.,LTD.',
profession : 'Android Development',
}
'me' = {
name : 'Kenju Wagatsuma ( KJ )’,
company : 'Recruit Technologies Co.,LTD.',
profession : 'Android Development',
favs : {
'Book' : ‘Soft Skills',
'Music' : ‘The Beatles',
'Hobby' : ‘Acoustic Guitar',
'Sport' : 'Rugby'
}
}
/**
* My Story
*
* @author me
*/
```java
/**
* Validate user id input from a form
*
* @param String userID
*/
private void validateUserId(String userId) {
// Validate userId
}
```
```java
private void validateUserId(String userId) {
// Check input field here
if (userId == null || userId.length() == 0) {
return;
}
// Validate userId
}
```
```java
// Utility class
public static class UtilClass {
public static boolean checkStringInput(String str) {
if (str == null || str.length() == 0) {
return true;
} else {
return false;
}
}
}
// Activity class
public void MainActivity extends Activity {
private void validateUserId(String userId) {
if(UtilClass.checkStringInput(userId)) return;
// Validate userId
// ...
}
}
```
/**
* @codereview
*
*/
```java
private void validateUserId(String userId) {
// Check input field here
if (userId == null || userId.length() == 0) {
return;
}
// Validate userId
}
```
```java
private void validateUserId(String userId) {
// Check input field here
if (TextUtils.isEmpty(userId)) {
return;
}
// Validate userId
}
```
Okay, I’ll look at the
source code, sir…
```java
/**
* Returns true if the string is null or 0-length.
* @param str the string to be examined
* @return true if str is null or zero length
*/
public static boolean isEmpty(CharSequence str) {
if (str == null || str.length() == 0)
return true;
else
return false;
}
```
……
……「いっしょやんけw」
```java
public static boolean checkStringInput(String str) {
if (str == null || str.length() == 0) {
return true;
} else {
return false;
}
}
```
My Code
```java
public static boolean isEmpty(CharSequence str) {
if (str == null || str.length() == 0)
return true;
else
return false;
}
```
android.TextUtils
```java
public static boolean checkStringInput(String str) {
if (str == null || str.length() == 0) {
return true;
} else {
return false;
}
}
```
My Code
```java
public static boolean isEmpty(CharSequence str) {
if (str == null || str.length() == 0)
return true;
else
return false;
}
```
android.TextUtils
……「いっしょやんけw」(再)
/**
* Why TextUtils?
* (not my own code)
*
*/
#47
「ライブラリーを知り、
ライブラリーを使う」
“Effective Java” 2nd Edition
#47
「ライブラリーを知り、ライブラリーを使う」
利点1
❖ 標準ライブラリを使用することで、それを書い
た専門家の知識と、それをあなたよりも前に使用
した人々の経験を利用することになります。
“Effective Java” 2nd Edition
#47
「ライブラリーを知り、ライブラリーを使う」
利点2
❖ 自分の課題に少しばかり関連している問題に対
する場当たり的な解決策を書くことで、時間を無
駄にする必要が無い。
“Effective Java” 2nd Edition
#47
「ライブラリーを知り、ライブラリーを使う」
利点3
❖ 自分では何もしなくても、多くの人によって繰
り返し書き直されるコードは、時間と共にパ
フォーマンスが改善される(自分のコードではそ
うはいかない)。
“Effective Java” 2nd Edition
/**
* So what?
*
* @return Conclusion
*/
#47
「ライブラリーを知り、ライブラリーを使う」
For All Beginners,
1. Know Android Library
2. Use Library methods
3. See & Understand source codes
3 Steps for Learning,
/**
* Appendix
*
*/
❖ android.text.format.DateUtils
❖ android.text.format.Formatter
❖ android.text.TextUtils
❖ android.text.util.Linkify
❖ android.util.Pair<F, S>
❖ android.util.SparseArray<E>
❖ android.util.Log
❖ android.util.LruCache
❖ android.graphics.Color
❖ android.media.ThumbnailUtils
android.*
android.text.TextUtils
```java
/**
* 与えられた文字列がすべて数値かどうかを判定
*/
public static boolean isDigitsOnly(CharSequence str) {
final int len = str.length();
for (int i = 0; i< len; i++) {
if (!Character.isDigit(str.charAt(i)) {
return false;
}
}
return true;
}
```
android.text.TextUtils
```java
/**
* HTMLエンコード
*/
public static boolean htmlEncode(String s) {
StringBuilder sb = new StringBuilder();
char c;
for (int i = 0; i < s.length(); i++) {
c = s.charAt(i);
switch(c) {
case '<':
sb.append("&lt;");
break;
//...その他のエンコードすべき文字
default:
sb.append(c);
}
}
return sb.toString();
}
android.text.TextUtils
```java
/**
* trim()で削除された空白の数を返します
*/
public static int getTrimmedLength(CharSequence s) {
int len = s.length();
int start = 0;
while (start < len && s.charAt(start) <= ' ') {
start++;
}
int end = 0;
while (end > start && s.charAt(end - 1) <= ' ') {
end--;
}
return end - start;
}
```
android.database.DatabaseUtils
```java
/**
* WHERE句作成のヘルパーメソッド
*/
public static String concatenateWhere(String a, String b) {
if (TextUtils.isEmpty(a)) {
return b;
}
if (TextUtils.isEmpty(b)) {
return a;
}
return "(" + a + ") AND (" + b + ")";
}
```
android.database.DatabaseUtils
```java
/**
* Cursorの中身を出力するデバッグ用メソッド
*/
public static void dumpCursor(Cursor cursor) {
dumpCursor(cursor, System.out);
}
public static void dumpCursor(Cursor cursor, PrintStream stream) {
stream.println(">>>>> Dumping cursor " + cursor);
if (cursor != null) {
int startPos = cursor.getPosition();
cursor.moveToPosition(-1);
while (cursor.moveToNext()) {
dumpCurrentRow(cursor, stream);
}
cursor.moveToPosition(startPos);
}
stream.println("<<<<<");
}
```
android.database.DatabaseUtils
```java
/**
* Cursorの現在の行を出力する
*/
public static void dumpCurrentRow(Cursor cursor, PrintStream stream) {
String[] cols = cursor.getColumnNames();
stream.println("" + cursor.getPosition() + " {");
int length = cols.length;
for (int i = 0; i < length; i++) {
String value;
try {
value = cursor.getString(i);
} catch (SQLiteException e) {
value = "<unprintable>";
}
stream.println(" " + cols[i] + '=' + value);
}
stream.println("}");
}
```
/**
* And Much More!
*
* Happy Coding!
*
*/

Contenu connexe

Tendances

お前は PHP の歴史的な理由の数を覚えているのか
お前は PHP の歴史的な理由の数を覚えているのかお前は PHP の歴史的な理由の数を覚えているのか
お前は PHP の歴史的な理由の数を覚えているのかKousuke Ebihara
 
Brief introduction of Boost.ICL
Brief introduction of Boost.ICLBrief introduction of Boost.ICL
Brief introduction of Boost.ICLyak1ex
 
オブジェクト指向を学ぼう
オブジェクト指向を学ぼうオブジェクト指向を学ぼう
オブジェクト指向を学ぼうYusuke Kikuchi
 
shared_ptr & weak_ptr (ppt 第2版, DL 専用)
shared_ptr & weak_ptr (ppt 第2版, DL 専用)shared_ptr & weak_ptr (ppt 第2版, DL 専用)
shared_ptr & weak_ptr (ppt 第2版, DL 専用)Cryolite
 
shared_ptr & weak_ptr (ppt 初版, DL 専用)
shared_ptr & weak_ptr (ppt 初版, DL 専用)shared_ptr & weak_ptr (ppt 初版, DL 専用)
shared_ptr & weak_ptr (ppt 初版, DL 専用)Cryolite
 
Continuation with Boost.Context
Continuation with Boost.ContextContinuation with Boost.Context
Continuation with Boost.ContextAkira Takahashi
 
20分くらいでわかった気分になれるC++20コルーチン
20分くらいでわかった気分になれるC++20コルーチン20分くらいでわかった気分になれるC++20コルーチン
20分くらいでわかった気分になれるC++20コルーチンyohhoy
 
競技プログラミングのためのC++入門
競技プログラミングのためのC++入門競技プログラミングのためのC++入門
競技プログラミングのためのC++入門natrium11321
 
C++ ポインタ ブートキャンプ
C++ ポインタ ブートキャンプC++ ポインタ ブートキャンプ
C++ ポインタ ブートキャンプKohsuke Yuasa
 
組み込み関数(intrinsic)によるSIMD入門
組み込み関数(intrinsic)によるSIMD入門組み込み関数(intrinsic)によるSIMD入門
組み込み関数(intrinsic)によるSIMD入門Norishige Fukushima
 
オブジェクト指向できていますか?
オブジェクト指向できていますか?オブジェクト指向できていますか?
オブジェクト指向できていますか?Moriharu Ohzu
 

Tendances (13)

お前は PHP の歴史的な理由の数を覚えているのか
お前は PHP の歴史的な理由の数を覚えているのかお前は PHP の歴史的な理由の数を覚えているのか
お前は PHP の歴史的な理由の数を覚えているのか
 
Brief introduction of Boost.ICL
Brief introduction of Boost.ICLBrief introduction of Boost.ICL
Brief introduction of Boost.ICL
 
オブジェクト指向を学ぼう
オブジェクト指向を学ぼうオブジェクト指向を学ぼう
オブジェクト指向を学ぼう
 
shared_ptr & weak_ptr (ppt 第2版, DL 専用)
shared_ptr & weak_ptr (ppt 第2版, DL 専用)shared_ptr & weak_ptr (ppt 第2版, DL 専用)
shared_ptr & weak_ptr (ppt 第2版, DL 専用)
 
shared_ptr & weak_ptr (ppt 初版, DL 専用)
shared_ptr & weak_ptr (ppt 初版, DL 専用)shared_ptr & weak_ptr (ppt 初版, DL 専用)
shared_ptr & weak_ptr (ppt 初版, DL 専用)
 
Fabrication
FabricationFabrication
Fabrication
 
Continuation with Boost.Context
Continuation with Boost.ContextContinuation with Boost.Context
Continuation with Boost.Context
 
Cocoa勉強会201208
Cocoa勉強会201208Cocoa勉強会201208
Cocoa勉強会201208
 
20分くらいでわかった気分になれるC++20コルーチン
20分くらいでわかった気分になれるC++20コルーチン20分くらいでわかった気分になれるC++20コルーチン
20分くらいでわかった気分になれるC++20コルーチン
 
競技プログラミングのためのC++入門
競技プログラミングのためのC++入門競技プログラミングのためのC++入門
競技プログラミングのためのC++入門
 
C++ ポインタ ブートキャンプ
C++ ポインタ ブートキャンプC++ ポインタ ブートキャンプ
C++ ポインタ ブートキャンプ
 
組み込み関数(intrinsic)によるSIMD入門
組み込み関数(intrinsic)によるSIMD入門組み込み関数(intrinsic)によるSIMD入門
組み込み関数(intrinsic)によるSIMD入門
 
オブジェクト指向できていますか?
オブジェクト指向できていますか?オブジェクト指向できていますか?
オブジェクト指向できていますか?
 

En vedette

【Potatotips #23】手軽にHTTPでJSONにアクセスできる環境を用意する
【Potatotips #23】手軽にHTTPでJSONにアクセスできる環境を用意する【Potatotips #23】手軽にHTTPでJSONにアクセスできる環境を用意する
【Potatotips #23】手軽にHTTPでJSONにアクセスできる環境を用意するHiroyuki Kusu
 
Androidでライブラリを作る
Androidでライブラリを作るAndroidでライブラリを作る
Androidでライブラリを作るShigeki Yamato
 
隕石という名のスクリーンショットをSlackに落下させる話
隕石という名のスクリーンショットをSlackに落下させる話隕石という名のスクリーンショットをSlackに落下させる話
隕石という名のスクリーンショットをSlackに落下させる話Shinobu Okano
 
Is Activity God? ~ The MVP Architecture ~
Is Activity God? ~ The MVP Architecture ~Is Activity God? ~ The MVP Architecture ~
Is Activity God? ~ The MVP Architecture ~Ken William
 
Design pattern in android
Design pattern in androidDesign pattern in android
Design pattern in androidJay Kumarr
 

En vedette (6)

【Potatotips #23】手軽にHTTPでJSONにアクセスできる環境を用意する
【Potatotips #23】手軽にHTTPでJSONにアクセスできる環境を用意する【Potatotips #23】手軽にHTTPでJSONにアクセスできる環境を用意する
【Potatotips #23】手軽にHTTPでJSONにアクセスできる環境を用意する
 
Androidでライブラリを作る
Androidでライブラリを作るAndroidでライブラリを作る
Androidでライブラリを作る
 
隕石という名のスクリーンショットをSlackに落下させる話
隕石という名のスクリーンショットをSlackに落下させる話隕石という名のスクリーンショットをSlackに落下させる話
隕石という名のスクリーンショットをSlackに落下させる話
 
Is Activity God? ~ The MVP Architecture ~
Is Activity God? ~ The MVP Architecture ~Is Activity God? ~ The MVP Architecture ~
Is Activity God? ~ The MVP Architecture ~
 
Design pattern in android
Design pattern in androidDesign pattern in android
Design pattern in android
 
Software Design patterns on Android English
Software Design patterns on Android EnglishSoftware Design patterns on Android English
Software Design patterns on Android English
 

Similaire à Don't Reinvent The Wheel ~ For All Android Beginners ~

C++0x in programming competition
C++0x in programming competitionC++0x in programming competition
C++0x in programming competitionyak1ex
 
C++0x in programming competition
C++0x in programming competitionC++0x in programming competition
C++0x in programming competitionyak1ex
 
GADTブランチの今
GADTブランチの今GADTブランチの今
GADTブランチの今啓 小笠原
 
Python standard 2022 Spring
Python standard 2022 SpringPython standard 2022 Spring
Python standard 2022 Springanyakichi
 
ぱっと見でわかるC++11
ぱっと見でわかるC++11ぱっと見でわかるC++11
ぱっと見でわかるC++11えぴ 福田
 
TypeScript 1.0 オーバービュー
TypeScript 1.0 オーバービューTypeScript 1.0 オーバービュー
TypeScript 1.0 オーバービューAkira Inoue
 
20141128 iOSチーム勉強会 My Sweet Swift
20141128 iOSチーム勉強会 My Sweet Swift20141128 iOSチーム勉強会 My Sweet Swift
20141128 iOSチーム勉強会 My Sweet Swiftnecocen
 
Processing workshop v3.0
Processing workshop v3.0Processing workshop v3.0
Processing workshop v3.0Wataru Kani
 
拡張可能でprintfっぽい書式指定ができて書式指定文字列と引数をコンパイル時に検証できる文字列フォーマット関数を作った
拡張可能でprintfっぽい書式指定ができて書式指定文字列と引数をコンパイル時に検証できる文字列フォーマット関数を作った拡張可能でprintfっぽい書式指定ができて書式指定文字列と引数をコンパイル時に検証できる文字列フォーマット関数を作った
拡張可能でprintfっぽい書式指定ができて書式指定文字列と引数をコンパイル時に検証できる文字列フォーマット関数を作ったdigitalghost
 
WPD-Fes #3 2015年のサバイバル学習術 Web開発技術の税引後利益 を最大化しよう!
WPD-Fes #3 2015年のサバイバル学習術 Web開発技術の税引後利益 を最大化しよう!WPD-Fes #3 2015年のサバイバル学習術 Web開発技術の税引後利益 を最大化しよう!
WPD-Fes #3 2015年のサバイバル学習術 Web開発技術の税引後利益 を最大化しよう!文樹 高橋
 
人生がときめくAPIテスト自動化 with Karate
人生がときめくAPIテスト自動化 with Karate人生がときめくAPIテスト自動化 with Karate
人生がときめくAPIテスト自動化 with KarateTakanori Suzuki
 
Unity C#3からC#6に向けて
Unity C#3からC#6に向けてUnity C#3からC#6に向けて
Unity C#3からC#6に向けてonotchi_
 
Burikaigi 2023「C# Live Coding!」 小島の分
Burikaigi  2023「C# Live Coding!」 小島の分Burikaigi  2023「C# Live Coding!」 小島の分
Burikaigi 2023「C# Live Coding!」 小島の分Fujio Kojima
 
GoCon 2015 Summer GoのASTをいじくって新しいツールを作る
GoCon 2015 Summer GoのASTをいじくって新しいツールを作るGoCon 2015 Summer GoのASTをいじくって新しいツールを作る
GoCon 2015 Summer GoのASTをいじくって新しいツールを作るMasahiro Wakame
 
イニシャライザー Part 2.5 #hakataswift
イニシャライザー Part 2.5 #hakataswiftイニシャライザー Part 2.5 #hakataswift
イニシャライザー Part 2.5 #hakataswiftTomohiro Kumagai
 
Synthesijer and Synthesijer.Scala in HLS-friends 201512
Synthesijer and Synthesijer.Scala in HLS-friends 201512Synthesijer and Synthesijer.Scala in HLS-friends 201512
Synthesijer and Synthesijer.Scala in HLS-friends 201512Takefumi MIYOSHI
 
TypeScript & 関数型講座 第2回 TypeScript という言語
TypeScript & 関数型講座 第2回 TypeScript という言語TypeScript & 関数型講座 第2回 TypeScript という言語
TypeScript & 関数型講座 第2回 TypeScript という言語gypsygypsy
 

Similaire à Don't Reinvent The Wheel ~ For All Android Beginners ~ (20)

C++0x in programming competition
C++0x in programming competitionC++0x in programming competition
C++0x in programming competition
 
C++0x in programming competition
C++0x in programming competitionC++0x in programming competition
C++0x in programming competition
 
GADTブランチの今
GADTブランチの今GADTブランチの今
GADTブランチの今
 
Python standard 2022 Spring
Python standard 2022 SpringPython standard 2022 Spring
Python standard 2022 Spring
 
C#6.0の新機能紹介
C#6.0の新機能紹介C#6.0の新機能紹介
C#6.0の新機能紹介
 
Map
MapMap
Map
 
ぱっと見でわかるC++11
ぱっと見でわかるC++11ぱっと見でわかるC++11
ぱっと見でわかるC++11
 
TypeScript 1.0 オーバービュー
TypeScript 1.0 オーバービューTypeScript 1.0 オーバービュー
TypeScript 1.0 オーバービュー
 
20141128 iOSチーム勉強会 My Sweet Swift
20141128 iOSチーム勉強会 My Sweet Swift20141128 iOSチーム勉強会 My Sweet Swift
20141128 iOSチーム勉強会 My Sweet Swift
 
Processing workshop v3.0
Processing workshop v3.0Processing workshop v3.0
Processing workshop v3.0
 
拡張可能でprintfっぽい書式指定ができて書式指定文字列と引数をコンパイル時に検証できる文字列フォーマット関数を作った
拡張可能でprintfっぽい書式指定ができて書式指定文字列と引数をコンパイル時に検証できる文字列フォーマット関数を作った拡張可能でprintfっぽい書式指定ができて書式指定文字列と引数をコンパイル時に検証できる文字列フォーマット関数を作った
拡張可能でprintfっぽい書式指定ができて書式指定文字列と引数をコンパイル時に検証できる文字列フォーマット関数を作った
 
CLR/H No.35-2
CLR/H No.35-2CLR/H No.35-2
CLR/H No.35-2
 
WPD-Fes #3 2015年のサバイバル学習術 Web開発技術の税引後利益 を最大化しよう!
WPD-Fes #3 2015年のサバイバル学習術 Web開発技術の税引後利益 を最大化しよう!WPD-Fes #3 2015年のサバイバル学習術 Web開発技術の税引後利益 を最大化しよう!
WPD-Fes #3 2015年のサバイバル学習術 Web開発技術の税引後利益 を最大化しよう!
 
人生がときめくAPIテスト自動化 with Karate
人生がときめくAPIテスト自動化 with Karate人生がときめくAPIテスト自動化 with Karate
人生がときめくAPIテスト自動化 with Karate
 
Unity C#3からC#6に向けて
Unity C#3からC#6に向けてUnity C#3からC#6に向けて
Unity C#3からC#6に向けて
 
Burikaigi 2023「C# Live Coding!」 小島の分
Burikaigi  2023「C# Live Coding!」 小島の分Burikaigi  2023「C# Live Coding!」 小島の分
Burikaigi 2023「C# Live Coding!」 小島の分
 
GoCon 2015 Summer GoのASTをいじくって新しいツールを作る
GoCon 2015 Summer GoのASTをいじくって新しいツールを作るGoCon 2015 Summer GoのASTをいじくって新しいツールを作る
GoCon 2015 Summer GoのASTをいじくって新しいツールを作る
 
イニシャライザー Part 2.5 #hakataswift
イニシャライザー Part 2.5 #hakataswiftイニシャライザー Part 2.5 #hakataswift
イニシャライザー Part 2.5 #hakataswift
 
Synthesijer and Synthesijer.Scala in HLS-friends 201512
Synthesijer and Synthesijer.Scala in HLS-friends 201512Synthesijer and Synthesijer.Scala in HLS-friends 201512
Synthesijer and Synthesijer.Scala in HLS-friends 201512
 
TypeScript & 関数型講座 第2回 TypeScript という言語
TypeScript & 関数型講座 第2回 TypeScript という言語TypeScript & 関数型講座 第2回 TypeScript という言語
TypeScript & 関数型講座 第2回 TypeScript という言語
 

Don't Reinvent The Wheel ~ For All Android Beginners ~