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:
...
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 ...
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 ...
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 ...
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 ...
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, ...
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 ...
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 ...
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.:
...
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 ...
6
votes
Accepted
Anagram Generator
for (word in wordList) {
...
val dictionary = File("dict.txt")
.readLines()
...
}
On the assumption that ...
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 ...
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".
<...
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 ...
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 ...
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. ...
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 ...
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 ...
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 ...
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:
...
5
votes
Accepted
Mastermind game in Kotlin
You could go for a more functional (rather than imperative) approach.
Such as:
...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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:
...
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 <...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
kotlin × 246android × 67
beginner × 22
algorithm × 15
java × 13
object-oriented × 9
functional-programming × 9
performance × 8
design-patterns × 8
programming-challenge × 7
strings × 7
spring × 7
array × 6
game × 6
parsing × 6
json × 6
generics × 6
mvvm × 6
kotlin-compose × 6
recursion × 5
primes × 5
api × 5
extension-methods × 5
rx-java × 5
hash-map × 4