Skip to main content
17 votes

Compiling and throwing simple dynamic exceptions at runtime for JVM

Is there anything that can be simplified or made even cleaner? Yes, don't invoke the Java compiler at runtime. From your examples in a comment: ...
Simon Forsberg's user avatar
13 votes
Accepted

Swift-function which counts the letters, numbers, spaces, special chars in a given string

Returning an array What's your opinion about returning the results in an array? Why would you do that? Because it's an easy way to return the result? Because you don't know how else to do it? How ...
Simon Forsberg's user avatar
12 votes

Count the number of duplicated chars in a string

A more straight forward solution would be to count each character and then to count the characters that have a count larger than 1. This can easily be done using the functional methods available in ...
RoToRa's user avatar
  • 11.4k
11 votes
Accepted

Arithmetic Parser in Kotlin

You are using a lot of nullable types, combined with non-null assertions (!!). This defeats the purpose of using the nullable types in the first place. You should ...
Simon Forsberg's user avatar
10 votes
Accepted

Event-driven finite state machine DSL in Kotlin

I'd design the StateMachine differently. The StateMachine does not need to know about all the possible Transitions between the States. All the StateMachine should care about is the current State it ...
D3xter's user avatar
  • 281
8 votes

Produce an arithmetic progression

I don't know this language, so I'll leave syntax-level reviews to others, and focus on the high-level aims. Some things to consider: You tested for step == 0, ...
Toby Speight's user avatar
  • 81.7k
7 votes
Accepted

Count the number of duplicated chars in a string

Some little things. The count is already counted by ArrayList(), with the for() loop you can't miss/forget a i++ and with the c there is no need for another ...
Holger's user avatar
  • 351
7 votes
Accepted

Constructing a DSL with properties instead of functions, for use in a type-safe pseudo-builder

I found your code to be very interesting and I'd like to thank you for putting it up for review. You are doing some things here that I found very interesting, especially the usage of returning a ...
Simon Forsberg's user avatar
7 votes

Swift-function which counts the letters, numbers, spaces, special chars in a given string

Two more ways in addition to Simon's excellent answer: The Char class has convenient methods like isDigit(), isLetter(), etc.: ...
lukas.j's user avatar
  • 244
6 votes
Accepted

Observer pattern using a set of observers and delegated properties

You don't need a wasPresent variable. MutableSet.add returns true if the ...
mfulton26's user avatar
  • 691
6 votes
Accepted

Anagram Generator

for (word in wordList) { ... val dictionary = File("dict.txt") .readLines() ... } On the assumption that ...
Peter Taylor's user avatar
  • 24.2k
6 votes
Accepted

Red Black Tree Implementation in Kotlin

Simplification You don't need two separate variables for REDness and BLACKness. You can just have one boolean variable ...
T145's user avatar
  • 3,137
6 votes
Accepted

Quiz for random boolean expressions

Very fun game you created here, I like it. Your calculations for the probabilities are also impressive, and well tested. Some small suggestions: UI improvement: Print a message when "leveling up". <...
Simon Forsberg's user avatar
6 votes
Accepted

Kotlin Goal Oriented Action Planning

This is quite a lot to analyze, so I will focus only few examples on semantics, best practices and language features. Naming Good: Have a structure well understandable not too long Arguable: Some ...
Neo's user avatar
  • 316
6 votes

Count the number of duplicated chars in a string

lowerCase and uppercase should be treated te same? Let's make them the same: val lowerText = text.toLowerCase() Check for duplicates? A set doesn't allow ...
tieskedh's user avatar
  • 822
6 votes
Accepted

Code for sorting items in recyclerView

You're right that the duplicate code in the sorters looks bad. To solve this, each sorter should only define the compare function, and all the rest should be done by the enum class. Or not even this. ...
Roland Illig's user avatar
  • 21.4k
6 votes

Are these Unit tests OK or am I implementing an antipattern or not following best practices

Some Concepts I'm not much experienced in the framework used but Unit Testing, Test Driven Development and Behavioral Driven Development are concepts that need to be understood well and then ...
Anit Shrestha's user avatar
6 votes
Accepted

Mapping named parameters to indices for PreparedStatement

Name of the class doesn't indicate its purpose. The class is called "ParameterMap" but its use-case (filling in values in a query) doesn't need to know about it having a map somewhere inside ...
QuasiStellar's user avatar
  • 2,237
5 votes
Accepted

Christmas Tree in Kotlin

"args" is more common and descriptive than "a" in a main function signature "\n" is system-dependent; I recommend using ...
mfulton26's user avatar
  • 691
5 votes
Accepted

Kotlin text validation

First of all, make attention - your code twice convert and check value. Suppose it's not efficient. Another tiny problem - 1280 and 1500 values is not change prefs.mtuSize… My code: ...
Victor Dmitrienko's user avatar
5 votes
Accepted

Mastermind game in Kotlin

You could go for a more functional (rather than imperative) approach. Such as: ...
Konrad Morawski's user avatar
5 votes
Accepted

Compiling and throwing simple dynamic exceptions at runtime for JVM

Setting isAccessible to true You seem to be always settings isAccessible to true. This is only needed if you are accessing ...
Ferrybig's user avatar
  • 1,357
5 votes

The Best™ class

The question whether to use (T) -> Double or Comparator<T> probably depends on your use case. If you have a scenario ...
RoToRa's user avatar
  • 11.4k
5 votes

WebService to calculate transaction statistics

I will have to agree that you do have a bit much synchronized blocks. All of them could go away if you would use for example ...
Simon Forsberg's user avatar
5 votes
Accepted

Kotlin fake properties and their usage

Generally speaking, I would not expect a database call to be made simply by referring to a property, such as with val user = MyRepository.userInfo. If a database ...
Simon Forsberg's user avatar
5 votes

Chess game in Kotlin

There's several parts of your design that can be improved. There is currently lots of duplicate code regarding color, allowed moves, and Pawn1, Pawn2, Pawn3 etc. Is there really any difference between ...
Simon Forsberg's user avatar
5 votes
Accepted

Create two teams from a list of players with minimum of one goalkeeper per team

{ player -> player.isGoalkeeper } can be replaced with (Player::isGoalkeeper) in all the places you're using it. This is ...
Tenfour04's user avatar
  • 813
5 votes

Calculator App with Kotlin and Android Studio

Crash Dividing by 0 crashes the app ungracefully. Detect this and show an error message. Warnings Check your "Problems" tab in Android studio. It tells you to use ...
ggorlen's user avatar
  • 3,987
5 votes

Android - A way to show/hide loader without writting false/true in every viewmodelScope.launch

If I interpret it correctly, you can basically wrap everything in a single method, and pass it a lambda: ...
Simon Forsberg's user avatar
5 votes
Accepted

Compose Grid With Lists

Looks quite good already, I haven't found any serious issues. The are some minor improvements that I would suggest, though. Small bugs I'm not sure how your data source looks like, but you import <...
tyg's user avatar
  • 438

Only top scored, non community-wiki answers of a minimum length are eligible