miyohideの日記

技術的なメモなどを記しています

2019年2月7日(木)

適当に書いたツールに対して久しぶりにメンテナンスの依頼が。もう完全にすべてを忘れている。

リファクタリング

ちょっと前まで既存アプリのリファクタリングを行っていたんですが、これがまあ大変。機能的に変化はないので効果は見えにくいんだけれども、将来的なことを考えるとやらないといけないわで...。

そんな中、@joker1007さんの発表資料を見かけて色々と納得。

speakerdeck.com

スライドの13ページに有るパラメータオブジェクトについて知識がなかったので、検索したら翻訳記事を見つけました。

techracho.bpsinc.jp

14ページに有るストラテジーパターンはこちらのサイトを見て思い出しました。GoFとか昔は厨ニ的に使ってたなあ。

morizyun.github.io

あとは「仕様は絶対ではない」ってことを強く意識するってことかな。リファクタリングに限らないけれども。顧客が言ったことは絶対って信じ込むのではなく、ちょっと調整してみるといろんなケースで楽になるような気がしている。

2019年2月6日(水)

最近、コード書いてないな。入院していたししょうがないか。

Rubyイディオム

Rubyには便利なメソッドがたくさんあるのですが、知らないと使えない...って至極当然のことを書いていますが、愚直にforを回すよりも良い書き方があることが多いです。そんなことを紹介してくれるブログ記事 がマネーフォワード エンジニアブログにありました。今日現在で3本。

配列版 moneyforward.com

Hash版 moneyforward.com

文字列版 moneyforward.com

どれも知っておくべき内容。勉強になりました。

2019年2月5日(火)

昨年、骨折をしたのですがそのときに入れたプレートなどの金属を取り除く手術をしました。取り急ぎ、無事です。

CSS Grid Layout

Bootstrapで横幅を12個のカラムに分けてレイアウトを作ることをよくやっているのですが、そのためだけにBootstrapを入れるのもなんだかなあと思っていました。あと、どうしても作るサイトが似たり寄ったりな感じになってしまうのもなんだかデザインの幅がないなあと。

そんなときに見つけたのが、CSS Grid Layoutです。CSS標準でグリッドレイアウトが定義できる感じ。ICS MEDIAさんの記事が参考になりました。

ics.media

企業サイトを作っているとどうしてもIE対応が必要となってくるのですが、そんなにコストを払わなくても対応できそうです。

あとは趣味で作っているサイトもBootstrap依存を外したいと思っていたのでちょっとこれはチャレンジしてみたい。

htmlreference.io/cssreference.io

上のCSS Grid Layoutを調べていたときに見つけたのですが、HTMLタグやCSSプロパティの使用例を示しているサイト。

htmlreference.io

cssreference.io

HTMLはだいたい頭に入っているんだけれども、CSSについてはかなり怪しいので、こういうサイトとかで知識をため込んでおきたい。

2019年1月28日(月)

Rubyist Magazine 0059号をリリースした。このリリース作業、楽にしたい。

個人でつくるwebサービス

speakerdeck.com

willnetさんの発表資料。

turbolinksはrails newの段階で--skip-turbolinksをつけて最初っから組み込まないようにしているのですが、ちょっと試してみようかなと。そもそもturbolinksを使いたくない理由が「動作がよく分からない」だったので、このスライドでなんとなく理解できた気がする。stimulusもはじめて知ったのでちょっと試してみたい。

github.com

2019年1月22日(火)

なんかバタバタ忙しい

license-gradle-pluginがうまく動いた

1月17日の日記で、license-gradle-pluginがうまく動かないということを書いた。

miyohide.hatenadiary.jp

ようやく解決方法がわかった。

./gradlew dependenciesの出力結果がヒントになった。

$  ./gradlew dependencies

> Task :dependencies

------------------------------------------------------------
Root project
------------------------------------------------------------

annotationProcessor - Annotation processors and their dependencies for source set 'main'.
No dependencies

apiElements - API elements for main. (n)
No dependencies

archives - Configuration for archive artifacts.
No dependencies

bootArchives - Configuration for Spring Boot archive artifacts.
No dependencies

compile - Dependencies for source set 'main' (deprecated, use 'implementation' instead).
No dependencies

compileClasspath - Compile classpath for source set 'main'.
\--- org.springframework.boot:spring-boot-starter -> 2.1.2.RELEASE
     +--- org.springframework.boot:spring-boot:2.1.2.RELEASE
     |    +--- org.springframework:spring-core:5.1.4.RELEASE
     |    |    \--- org.springframework:spring-jcl:5.1.4.RELEASE
     |    \--- org.springframework:spring-context:5.1.4.RELEASE
     |         +--- org.springframework:spring-aop:5.1.4.RELEASE
(以下省略)

ここでcompileの部分がNo dependenciesになっているからlicense-gradle-pluginを動かしても空だったんだ。そこで、build.gradleに以下を追加する。

downloadLicenses {
    dependencyConfiguration = 'runtimeClasspath'
}

runtimeClasspathの部分は./gradlew dependenciesの出力結果から良さげなものを選んだ。これで./gradlew downloadLicensesを実行すると、

$ ./gradlew downloadLicenses

BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed

$ ls -l build/reports/license/
total 80
-rw-r--r--  1 miyohide  staff  8674  1 22 21:50 dependency-license.html
-rw-r--r--  1 miyohide  staff  3828  1 22 21:50 dependency-license.json
-rw-r--r--  1 miyohide  staff  4436  1 22 21:50 dependency-license.xml
-rw-r--r--  1 miyohide  staff  4320  1 22 21:50 license-dependency.html
-rw-r--r--  1 miyohide  staff  1440  1 22 21:50 license-dependency.json
-rw-r--r--  1 miyohide  staff  2002  1 22 21:50 license-dependency.xml

$ more build/reports/license/dependency-license.json
{"dependencies":[{"name":"org.springframework:spring-expression:5.1.4.RELEASE","file":"spring-expression-5.1.4.RELEASE.jar","licenses":[{"name":"Apache License, Version 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0"}]},{"name":"org.springframework:spring-aop:5.1.4.RELEASE","file":"spring-aop-5.1.4.RELEASE.jar","licenses":[{"name":"Apache License, Version 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0"}]},{"name":"org.springframework.boot:spring-boot-starter:2
(以下省略)

やったあ。動いたあ。

2019年1月17日(木)

バタバタしていたらいつの間にか一週間以上更新できていなかった。

license-gradle-pluginがうまく動かない

Javaアプリで「アプリが使っているライブラリの一覧とそのライセンスを知りたい」ってニーズがあったので、何か無いかなと思い調べてたどり着いたのが、hierynomus/license-gradle-plugin。

github.com

早速、build.gradleプラグインを読み込ませる。

buildscript {
    ext {
        springBootVersion = '2.1.2.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}
// 以下3行を追加
plugins {
    id "com.github.hierynomus.license" version "0.15.0"
}

apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

あとは、./gradlew downloadLicensesと打って実行。

$ ./gradlew downloadLicenses

Welcome to Gradle 4.10.2!

Here are the highlights of this release:
 - Incremental Java compilation by default
 - Periodic Gradle caches cleanup
 - Gradle Kotlin DSL 1.0-RC6
 - Nested included builds
 - SNAPSHOT plugin versions in the `plugins {}` block

For more details see https://docs.gradle.org/4.10.2/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

BUILD SUCCESSFUL in 18s
1 actionable task: 1 executed

$

結果は、build/reports/license以下に出力されるみたい。

$ ls -l build/reports/license/
total 48
-rw-r--r--  1 miyohide  staff  1218  1 17 22:01 dependency-license.html
-rw-r--r--  1 miyohide  staff    19  1 17 22:01 dependency-license.json
-rw-r--r--  1 miyohide  staff    16  1 17 22:01 dependency-license.xml
-rw-r--r--  1 miyohide  staff  1198  1 17 22:01 license-dependency.html
-rw-r--r--  1 miyohide  staff    15  1 17 22:01 license-dependency.json
-rw-r--r--  1 miyohide  staff    12  1 17 22:01 license-dependency.xml

$

あれ?やたらとファイルサイズが小さい。ちょっと中身を見てみよう。

$ head build/reports/license/dependency-license.xml
<dependencies />
$

う〜ん、空だ。なんでだろう。

ちなみにbuild.gradleimplementation 'org.springframework.boot:spring-boot-starter'の部分をcompile 'org.springframework.boot:spring-boot-starter'とし、./gradlew clean && ./gradlew downloadLicensesを実行すると...

$ cat build/reports/license/dependency-license.xml
<dependencies>
  <dependency name='org.springframework:spring-expression:5.1.4.RELEASE'>
    <file>spring-expression-5.1.4.RELEASE.jar</file>
    <license name='Apache License, Version 2.0' url='http://www.apache.org/licenses/LICENSE-2.0' />
  </dependency>
(以下略)

う〜ん、きちんと出力される。

2019年1月8日(火)

ばたばた忙しい。

RailsスタイルからRESTを学ぼう

RailsでRESTを知って以来、何でもかんでもRESTでURLを設計してしまう自分。ただRESTって意外と説明が難しい。そんな中、@tkawaさんによる説明資料が素晴らしくわかりやすい。

www.slideshare.net

個人的には、P61のGraphQLが目指している特性とRESTとの違いを詳しく知りたいと感じた。

2019年のJava

Javaのリリースモデル変更については弊社内でも結構騒ぎになっている。そんな中見かけた解説ページ。あの有名な寺田佳央さんが書かれている。

gihyo.jp

むやみやたらに「最新バージョンに追いつけ」って書かれていないところが流石ですね。塩漬けにしたいシステムとか色々と頷きながら読んでました。

でも、今から作るのならちゃんとテストコード書こうよとも思います。