Language 69

[Style] no_leading_underscores_for_local_identifiers

다트 공식홈페이지에서 연습문제를 풀다가 no_leading_underscores_for_local_identifiers 를 알게되었다. (에디터에서 바로바로 경고창이 떠서 놀랐다!) https://dart-lang.github.io/linter/lints/no_leading_underscores_for_local_identifiers.html no_leading_underscores_for_local_identifiers no_leading_underscores_for_local_identifiers Group: style Maturity: stable View all Lint Rules Using the Linter DON’T use a leading underscore for identifiers t..

Language/Dart 2022.08.19

[Exercism] Armstrong Numbers #num #math

https://exercism.org/tracks/dart/exercises/armstrong-numbers Armstrong Numbers in Dart on Exercism Can you solve Armstrong Numbers in Dart? Improve your Dart skills with support from our world-class team of mentors. exercism.org 처음에 문제 조건을 잘못 이해해서 조금 해맸다. 먼저 제곱을 계산하기 위해 'dart:math' library를 사용하였다. 그리고 다트에서는 int.parse(String word)를 통해 String 숫자를 int로 변환할 수 있다.(double.parse도 있다!) math의 pow를 사용해서 각..

Language/Dart 2022.08.19

[Exercism] Scrabble Score #가독성 있는 코드란?2

https://exercism.org/tracks/dart/exercises/scrabble-score Scrabble Score in Dart on Exercism Can you solve Scrabble Score in Dart? Improve your Dart skills with support from our world-class team of mentors. exercism.org 이전 Leap랑 같이 가독성 있고, 수정하기 좋은 코드에 대해 얘기를 나눌 수 있었던 문제! 처음에 내가 문제를 풀었던 방식은 1) 단어별 점수 조건을 Map으로 만들고 + 2) 주어진 단어를 List로 변환해서 이중 for문을 사용해서 점수를 구했다. 여기서 또 알게된 재밌는 사실은, 다트는 .dart 파일마다 반드..

Language/Dart 2022.08.18

[Exercism] Leap #가독성 있는 코드란?

https://exercism.org/tracks/dart/exercises/leap Leap in Dart on Exercism Can you solve Leap in Dart? Improve your Dart skills with support from our world-class team of mentors. exercism.org 처음에 문제가 이해되지 않아서(영어 해석이 안됬다...) 한참 헤매다가 테스트코드에 있는 조건들을 보고 문제를 풀었다. 그래서 내가 처음 냈던 답안은 아래와 같다. class Leap { bool leapYear(int year) { return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0); } } 문제를 풀면서 팀원과..

Language/Dart 2022.08.18

[Exercism] Two Fer #Optional positional parameters

https://exercism.org/tracks/dart/exercises/two-fer Two Fer in Dart on Exercism Can you solve Two Fer in Dart? Improve your Dart skills with support from our world-class team of mentors. exercism.org 다트는 optional positional parameters를 사용할 수 있다. 이렇게 default 값을 넣어 줄 수도 있고 String twoFer([String name = 'you']) { return 'One for ${name}, one for me.'; } 아니면 널을 허용한 상태(String?)에서 null일 경우를 분기 처리해주는 방법도..

Language/Dart 2022.08.18

Dart 공부하기

새로운 언어를 공부하게 되었다! 공식문서 https://dart.dev/ 비교적 최근에 나온 언어들이 그렇듯이 공식문서가 굉장히 잘되어있다. Dart programming language Dart is a client-optimized language for fast apps on any platform dart.dev 자바를 하다가 다트를 시작한 느낌은, 1. 객체지향 + 정적 + 컴파일러라서 접근하기 쉽다. 2. Null Safe!!!!! 3. 좀 더 간결하다(생성자의 new 등 자바에서는 반드시 써야했던 것이 많이 생략되어 있다.) DartPad DartPad를 통해 웹에서도 연습할 수 있다. https://dartpad.dev/? DartPad dartpad.dev Flutter를 위한 언어인만큼..

Language/Dart 2022.08.18

[프로그래머스] 예산

https://school.programmers.co.kr/learn/courses/30/lessons/12982?language=java 이 문제의 포인트는 두 가지이다. 1. 예산을 가장 많이 지급하려면, 신청한 금액이 적은 부서들에게 지급하면 된다. → 정렬 2. 지급한 금액이 budget 보다 크면 더 이상 지급할 수 없다. → break import java.util.Arrays; class Solution { public int solution(int[] d, int budget) { int answer = 0; int sum = 0; //1. 정렬 Arrays.sort(d); for (int i = 0; i < d.length; i++) { sum += d[i]; //2-1. 지급한 금액이 ..

Language/JAVA 2022.07.15

[프로그래머스] K번째수 #Arrays.copyOfRange

https://programmers.co.kr/learn/courses/30/lessons/42748?language=java 주어진 조건에 따라 배열에서 원하는 값을 찾아서, 배열로 출력하는 문제이다. int배열을 주어진 범위를 index로 잘라서 복사하는 메서드를 새로 알게 되었다. java.util.Arrays에 있는 메서드이다. 배열이기 때문에 from과 to가 배열의 범위를 벗어나면 에러가 발생한다. public static int[] copyOfRange(int[] original, int from, int to) { int newLength = to - from; if (newLength " + to)..

Language/JAVA 2022.07.01

[디자인패턴]controller pathvariable로 service 구현체 주입하기

인터페이스를 구현하는 여러 service 구현체가 있을 때, controller에서 pathvariable을 통해 구현체를 주입할 수 있다. 먼저 인터페이스를 하나 만들고, A와 B 두개의 구현체를 만들었다. public interface TestInterface { void save(); Type getType(); } @Service public class TestAImpl implements TestInterface { Type type; public Type getType() { return Type.A; } @Override public void save() { System.out.println("save A"); } } @Service public class TestBImpl implement..

Language/JAVA 2022.06.16

[Java with Unit Test] equals와 hashCode

넥스트스텝에 있는 를 시작했는데, 여기서 학습테스트를 소개하고 있다. https://edu.nextstep.camp/c/9WPRB0ys/ 플레이그라운드 edu.nextstep.camp 익숙하지 않은 API를 공부할 때 단위테스트를 작성하면 해당 API의 사용법도 알 수 있고, 단위테스트에도 익숙해질 수 있다. 코스 시작 부분에서 예제로 String의 몇몇 메서드들을 Junit과 AssertJ를 사용해 단위테스트를 작성하는 연습을 할 수 있다. 단위테스트를 통해 어떤 값이 들어가고, 그 결과가 어떻게 출력되는지 바로 알 수 있어서 좋다. 그래서 Java 공부를 할 겸 프로젝트를 하나 만들었다. Object 모든 클래스의 최고 조상이기 때문에 모든 클래스에서 바로 사용이 가능하다. equals(Object ..

Language/JAVA 2022.06.16