Swift が Android 上で動き始めてよく分かる Kotlin の素晴らしさ

Swift がAndroid上で動き始めており,

_RFC__Port_to_Android_by_modocache_·_Pull_Request__1442_·_apple_swift

[RFC] Port to Android by modocache · Pull Request #1442 · apple/swift

Hacker News でも少し話題になっていたので眺めておりました.

Swift_Ported_to_Android___Hacker_News

Swift Ported to Android | Hacker News

「Swift が Android上で動くこと」について話題がされているかと思いきや Kotlin と比較され, Kotlin のAndroid上で動かすことの良さがはっきりと分かるスレになっておりました.

Surprised noone mentions Kotlin. It's quite Swift-like, backed by JetBrains (Android Studio is based on their IntelliJ Idea), and 1.0 has only just been released. It has full interoperability with Java.

Kotlin に誰も言及していないのが驚き. Kotlin は Swift によくにており, JetBrains (AndroidStidioのベースとなるIntelliJ Idea の開発元)がバックアップしており, 1.0 がリリースされたばかりのもので Java と完全に相互連携ができる.

I love Kotlin, but being able to develop libraries in one language and use them in both Android and iOS is huge. I have been using J2Objc for this until now, and while it's a great tool, it forces me to use Java, which I don't love. I would prefer being able to use Kotlin on iOS, but using Swift for Android development is a great boon.

私はKotlinが好きだが, ひとつの言語でAndroidとiOSで開発ライブラリを利用可能にすることは大変だ. いままで J2Ojc を使っておりこれは素晴らしいツールでJavaを使うことを強いられるが私は好きではない. それより Kotlin を iOS上で利用可能にするほうがいい. Android開発にSwiftを使うのは 非常にありがたいのだが...

Kotlin emits bytecode. It is entirely interoperable with Java. All the Java APIs of the platform are accessible in Kotlin.
Swift on the other end can only target the NDK, which limits it to a very specific niche on Android.

Kotlin はバイトコードを吐く, これは Java と完全に相互連携できること. すべてのJavaAPI はKotlin で利用できる.
一方 Swift は Android上では NDKのみに限定され非常に狭い.

What helps a lot is that the kotlin team has written many helper methods allowing a better flow between the android API and kotlin code : while you don't need it in order to get interop, it allows to more easily write idiomatic kotlin code while interacting with Android.

Kotlin チームの書いたたくさんのヘルパーメソッドは, Android API と Kotlin 間の流れをより良くしており, Swift ユーザがそれを利用しないことと対照的に, Androidと連携しながらより簡単に慣用的な Kotlin コードを書くことができる.

The main problem with Swift on Android is that AFAIK it is going to be limited to NDK.
There is certainly a niche where it can be useful, but for most developers, it makes it a no go.
Kotlin on the other end is indeed a very good stand-in replacement for java on Android.

私の知る限りSwift を Android上で動かすことの大きな問題は NDKに限定されることだ. このことは確実に便利さを狭めておりそれが進行を妨げている. 一方, Kotlin は確かに Android 上での Java の代替となる.

No one cares if you don't use Swift. Go with Kotlin. It's probably a great choice for you. It seems like a great language and I hope it gains traction.

Swift は使わなくて良い. Kotlin でいこう. あなたにとって素晴らしい選択となる. 偉大な言語で勢いを増すことを願っている.

If all you're doing is Android programming Kotlin is probably a better choice at this time. If you're a Java programmer, Kotlin is probably a better choice. If you're already a Swift programmer...
Also, let's see how both languages gain traction in the next 3-5 years.

Androidプログラミングのみを行っていたり, Javaプログラマーであるなら Kotlin はおそらくより良い選択です. もしあなたがすでにSwiftプログラマーであるなら...
次の3-5年でそれぞれがどのように勢いを増すかを見ておきましょう.

しかし,「ことりん」て名前. かわいいよなあ.

あの「Hacker News」で ベストなストーリーを見つける方法


Stackoverflow の短い公式URLでコピペ用ブックマークレットを作る

例えば, この非常に有益なこのページ.

Difference between px, dp, dip and sp on Android? - Stack Overflow

コードの中に参照先として貼り付けていましたが長いのでどうにかならないものかな,と.

long_url

フツーにブラウザのURLバーから取得できるURLはこのような以下のような形式.

Question
http://stackoverflow.com/questions/2025282/difference-between-px-dp-dip-and-sp-on-android

Answer
http://stackoverflow.com/questions/2025282/difference-between-px-dp-dip-and-sp-on-android/2025541#2025541

調べてみると, URLの書式はたくさん存在していて以下のURLは すべて同じ Question「2025282」の Answer「2025541」を参照している.

http://stackoverflow.com/questions/2025282/difference-between-px-dp-dip-and-sp-on-android#answer-2025541

http://stackoverflow.com/questions/2025282/2025541#2025541

http://stackoverflow.com/questions/2025282/#2025541

http://stackoverflow.com/questions/2025541

http://stackoverflow.com/q/2025282/#2025541

http://stackoverflow.com/a/2025282/#2025541

Google ShortURL や TinyUrl などサービスを使わずに, ページ内「share」のリンクから取得できる形式の公式の短縮URLを利用したい.

Difference_between_px__dp__dip_and_sp_on_Android__-_Stack_Overflow

ログインしていない場合は,

Question:
http://stackoverflow.com/q/2025282

Answer:
http://stackoverflow.com/a/2025541

この場合,
「2025282」は, Question投稿のID.
「2025541」は, Answer投稿のID.

ログインしている場合だと,

Question:
http://stackoverflow.com/q/2025282/000000

Answer:
http://stackoverflow.com/a/2025541/000000

この場合,「000000」はログインしているユーザのID.

ということで, ログインしていないときの公式のshareリンククリックからのダイアログに表示するURL形式に合わせてURLバーのURL文字列から公式の短いURLに変換した文字列に「タイトル」を加えたものをすばやくコピーできるブックマークレットを作る.

[Title]
http://stackoverflow.com/q/[question_id]

[Title]
http://stackoverflow.com/a/[answer_id]

Question へのリンクであれば,

http://stackoverflow.com/questions/2025282/difference-between-px-dp-dip-and-sp-on-android

Difference between px, dp, dip and sp on Android?
http://stackoverflow.com/q/2025282

Answer へのリンクであれば,

http://stackoverflow.com/questions/2025282/difference-between-px-dp-dip-and-sp-on-android/2025541#2025541

Difference between px, dp, dip and sp on Android?
http://stackoverflow.com/a/2025541

で,

こんなブックマークレットに.

javascript:
var pathinfo = window.location.pathname.split('/');
window.prompt('', document.title + '\n' + 
  location.protocol + '//'+ location.host +
    (pathinfo[4] ? '/a/' + pathinfo[4] : '/q/' + pathinfo[2]));
void(0);

結果.

Difference_between_px__dp__dip_and_sp_on_Android__-_Stack_Overflow

ここで, コピーして貼る.

short_url

と短く収まるようになりました.

ログイン中でもユーザIDを含めずにタイトルを付けてかんたんにコピペできます.

ちなみに,

http://s.tk/so

http://stackoverflow.com/#

What shortened URLs are available through s.tk? - Meta Stack Exchange

とホスト部分も短縮できたりするらしいがまあいいか.

👉 まとも検索 検索オプション追加 のブックマークレット 


コマンドラインで stackoverflow を快速に検索できる「how2」

使い方はこうです.

usage: how2 [-l python/ruby/etc.] search string

コマンドである「how2」に続いて, 検索したいキーワードを入力します.

bz2

言語 (タグ?) を限定する場合はオプション「 -l 」を付けます.

例えば, キーワードを「retrolambda」「RxJava」として android 関連の情報を探します.

$ how2 -l android retrolambda rxjava

how2

さらに他に情報を見たい場合は [SPACE] を押すと一覧で表示されて選択できます.

__—_how2 2

__—_how2 3

__—_how2 4

これはもう「tldr」よりも広く分かりやすい説明をみつけることができそうです.

インストールは以下で.

$ brew install node
$ npm install -g how2

santinic/how2: stackoverflow from the terminal

man は長すぎるので「tldr」