너, 자바충이지? – 자바에 중독된 뇌를 고쳐라 1

뇌가 자바에 절여진 자바충들아 자바를 버려라

코틀린이라는 압도적인 솔루션이 나왔음에도 자바만을 고집하는 어리석은 자바충들이 이제라도 코틀린으로 넘어오길 바라며

자바충 특

  • 자바 버전올라가는거 싫어함
  • log4j 뉴스나오기 전까지 업데이트 안함
  • stream()쓰면 안되는 줄 앎
  • 리플렉션 쓰는거 싫어함

자바에 비해 코틀린은 문법이 유연하다

Entity to DTO코드 만들기 비교

자바충

엔티티 클래스에 public AccountDto toDto()
를 만들어서 꾸역꾸역 쑤셔넣는다
Entity, Dto가 상호 참조를 유지해야되서 좆같이 한 모듈에 쑤셔쳐박는다

코틀린 사용자

fun Entity.toDto()
으로 재미있게 만들 수 있고

  • presentation
  • service
  • model

그레이들 모듈로 레이어를 나눠서 사용하고 수 있다.
모듈화로presentation 레이어에서 Entity에 손도 못 대게 만들어둘 수 있다.

왜좋은지자세한설명은서버용량이부족해서생략
용량이부족해서띄어쓰기도생략

인도에서는 19단까지 외운다며?

표현의 풍부함은 사고의 프레임워크를 확장시켜준다

자바충의 사고방식에서 [1,2,3,4,5,6,7]에서 홀수를 꺼내려면 어떻게 해야할까?
더러워서 여기 쓰기도 싫다

kotlin way

fun filterOdd(input) = input.filter{ it % 2 != 0 }

apply, let, also, with, run, filter, sum, map 등등 처음엔 헷갈리는데
외워놓다보면 표현식이 점점 익숙해지면서 쓸데없는 부분에서 오버헤드가 사라진다.
못 외울정도는 아니기도 하고

null <> “”

아무리 자바충이라도 설마

null ? !!

귀찮다

EOF

Rails6 프로젝트에서 JS 설정방법 변화(Typescript)

변화 Gem -> Webpacker

예전에는 Gemfile에서 관리했다면

# gem 'coffee-rails'
# gem 'cljs-rails'
# gem 'typescript-rails', git: 'https://github.com/ScriptonBasestar-io/typescript-rails.git'

요즘에는 webpakcer를 통해 npm으로 관리한다.

    "typescript": "^3.8.3",

구조가 좀 바뀌었다.

rails new 하면 예전에는 coffeesciprt를 넣어줬는데
요즘엔 기본구성이 아래처럼 변경됐다.

# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'

예전에는 화면쪽 리소스가
/app/assets/stylesheets
/app/assets/javascript s???
에 있었고
stylesheet_link_tag
javascript_include_tag
를 사용했는데

webpacker를 사용하면서
/app/javascript/packs/**/*.(js|ts)
/app/javascript/stylesheets/**/*.(css|scss|sass)
에 파일을 놔두고
stylesheet_pack_tag
javascript_pack_tag
를 사용한다.

본좌는 stylesheet는 구 방식을 사용중이다
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%#= stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
하지만 스크립트는 웹팩으로
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>

그리고 아랫쪽에 스크립트를 넣어줬다.
모듈별
<%= javascript_pack_tag controller_name if pack_exists?(controller_name) %>
화면, 액션별
<%= javascript_pack_tag "#{controller_name}-#{action_name}" if pack_exists?("#{controller_name}-#{action_name}") %>

이런건 쓰지말자 웹팩이 캡술화를 시켜버려서 화면에다가 스크립트 박아넣으면 제대로 동작하지 않는다.
<%= yield :javascript %>

관리 포인트가 분리되서 더 좋은 것 같다.
예전엔 npm이 업데이트되고 gem이 업데이트되야 사용할 수 있었을텐데
이젠 npm 최신버전 적용이 더 수워졌을테니

turbolink 때문에 화면전환시 로딩이 줄어들지만
document.ready가 제대로 동작하지 않는 경우가 있으니 주의해야한다

$(document).on('turbolinks:load',function () {
});

RubyOnRails 회원/권한 관리 Framework 목록

회원관리 솔루션

Devise

제일 많이 사용되는 솔루션. 특별한 이유가 없다면 이걸 쓰면 된다.
https://github.com/heartcombo/devise

Clearance

https://github.com/thoughtbot/clearance

CanCan

더 이상 업데이트가 되지 않고 있다.
https://github.com/ryanb/cancan

CanCanCan

Devise에 비하면 Star도 적고 특별히 차별화 되어있지 않다. Devise가 질렸다면 써볼수도 있겠지만…

권한관리 솔루션

PunchIt

Authlogic

https://github.com/binarylogic/authlogic
가장 최근 생긴 프로젝트로 업데이트 잘 되고 있는 것 같다

자바 개발환경 구성 SCOOP 활용

https://scoop.sh/

파워셀 실행 후 아래명령 실행
(윈도우+x i)

Set-ExecutionPolicy RemoteSigned -scope CurrentUser
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')

스쿱 버킷추가

scoop bucket add extras
scoop bucket add java

자바도구 설치

scoop install gradle
scoop install maven
scoop install openjdk11
scoop install ojdkbuild8
scoop install scala
scoop install kotlin
scoop install groovy

한개씩 다운받아서 설치하는건 연습할 때만 하면 되고
이걸로 하면 자동으로 해줘서 편하다.

이걸 한개씩 설치하는 사람이 꽤 있는 것 같아서

Error: node yarn start 하자마자 발생하는 runtime 오류

에러메시지

/Users/archmagece/work/aprobit-service/apronode/node_modules/express/lib/router/index.js:458
      throw new TypeError('Router.use() requires a middleware function but got a ' + gettype(fn))
      ^

TypeError: Router.use() requires a middleware function but got a Object
    at Function.use (/Users/archmagece/work/aprobit-service/apronode/node_modules/express/lib/router/index.js:458:13)
    at Function.<anonymous> (/Users/archmagece/work/aprobit-service/apronode/node_modules/express/lib/application.js:220:21)
    at Array.forEach (<anonymous>)
    at Function.use (/Users/archmagece/work/aprobit-service/apronode/node_modules/express/lib/application.js:217:7)
    at Object.<anonymous> (/Users/archmagece/work/aprobit-service/apronode/app/app.js:22:5)
    at Module._compile (internal/modules/cjs/loader.js:1157:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1177:10)
    at Module.load (internal/modules/cjs/loader.js:1001:32)
    at Function.Module._load (internal/modules/cjs/loader.js:900:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
error Command failed with exit code 1.

에러발생 코드

app.use('/api/v2/public', require('./routes/public'))

해결

./routes/public.js 맨 아래에 다음코드 추가

module.exports = router;

export를 안했네.. 이런짓을???

노드에 익숙하지 않긴한데 에러메시지 보고 한번에 알아채지 못해서 약간의 시간낭비

React Components

컴포넌트 모음
https://github.com/brillout/awesome-react-components

Web

  • https://github.com/creativetimofficial/material-kit-react
  • https://github.com/mui-org/material-ui
  • https://github.com/designrevision/shards-react
  • https://github.com/react-bootstrap/react-bootstrap
  • https://github.com/bvaughn/react-virtualized
  • https://github.com/creativetimofficial/argon-design-system-react
  • https://github.com/palantir/blueprint
  • https://github.com/react-toolbox/react-toolbox
  • https://github.com/OnsenUI/OnsenUI
  • https://github.com/segmentio/evergreen
  • https://github.com/reactstrap/reactstrap
  • https://github.com/grommet/grommet
  • https://github.com/rebassjs/rebass
  • https://github.com/mlaursen/react-md

Desktop

  • https://github.com/gabrielbull/react-desktop

Native

  • https://github.com/jondot/awesome-react-native