News for hackers. Stuff that matters.

eriksencosta

Re:Terraform AWS Organization Foundation on Saturday May 16, 2026 @11:39AM (#48161141)
A production-ready AWS Organization foundation built with Terraform. This template codifies years of multi-account AWS best practices into a reusable, community-friendly blueprint.
Re:Kotlin Money on Friday October 11, 2024 @02:05AM (#41806659)
In my previous job, we had a mid-sized team of ~34 software engineers and Kotlin worked like a charm. We set common standards and practices early on and it paid off. The lone wolves will exist regardless of the programming language. I've seen them in different flavors: Ruby, Elixir, PHP, JS, Python, Perl, Java, Kotlin, and etecetera throughout my career. It's a matter of team dynamics.

Anyway, I'm not a Kotlin die-hard but I found it quite fun to code in the language. IMHO, it has a gentle learning curve and the community has plenty of great libraries (e.g., Ktor, Koin).

Nevertheless, I think I leaned too much on using the syntactic sugar of the language when writing the docs and the introductory article. But by no means users are bound to this way of coding.

Re:Kotlin Money on Friday October 11, 2024 @01:43AM (#41806546)
It's a shame I can't travel back in time. Anyway, thanks!
Re:Kotlin Money on Friday October 11, 2024 @01:35AM (#41806502)
Not yet to Android (in the case of the library). Need to revamp some internal things.
Re:Kotlin Money on Friday October 11, 2024 @01:30AM (#41806478)
I think it helps to have the inputs and outputs of the system fully representing a "money" (i.e., a monetary amount + its currency code in places like API resources, events, and so on). This way you can internationalize or support multi-currency processing if that's the case. That's (if I remember correctly) what the payment card services companies (e.g., Mastercard, Visa) do by default in their message exchanges when calling the issuer for transaction confirmation.

Anyway, the allocation may be tweaked to favour where the additional/missing pennies will be allocated. You can find more at: https://github.com/eriksencosta/money/blob/trunk/docs/usage/...

Re:Kotlin Money on Friday October 11, 2024 @01:18AM (#41806405)
HALF_EVEN by default using the minor units of each currency (based on CLDR/ICU datasets). Client code can disable rounding at all.

Check for more: https://github.com/eriksencosta/money/blob/trunk/docs/usage/...

Re:Kotlin Money on Friday October 11, 2024 @01:14AM (#41806386)
What do you think of this? https://github.com/eriksencosta/money/blob/enum-percentage-s...

It is a (quick) spike solution, but I've implemented the currency codes as enums and added support for 20.percent.

Not so sure about supporting 50.btc and 25.3.usd. I need to check if doing so would affect code completion.

Re:Kotlin Money on Tuesday October 08, 2024 @03:26PM (#41780859)
Excel macros.
Re:Kotlin Money on Tuesday October 08, 2024 @03:24PM (#41780838)
Yep, it is. However, you must create a custom currency to arbitrarily define the minor units you need: https://github.com/eriksencosta/money/blob/trunk/docs/usage/...
Re:Kotlin Money on Tuesday October 08, 2024 @03:13PM (#41780732)
I love to learn more about the history of computing. Thanks.
Re:Kotlin Money on Tuesday October 08, 2024 @03:12PM (#41780722)
The currency exchange support is way simpler than this. The library only provides a method that will calculate the monetary amount given another Money object as the rate:

val amount = 1 money "USD" // USD 1.00

val rate = 5.4905 money "BRL" // BRL 5.4905

amount exchange rate // BRL 5.49

It's up to implementers to hook up in other datasets and to consume the rates. Exchange rates datasets differ from country to country and some foreign exchange companies offer short-term contracts to hold a transaction at a given rate (sort of "guaranteed rate/price"). I don't see myself supporting this use case.

Nevertheless, Java Money (Moneta) has this feature. Never used it so, I don't know how it works.

Re:Kotlin Money on Tuesday October 08, 2024 @03:03PM (#41780640)
I'm very grateful so far by the comments. I've learned a lot and it will help me on the next iterations of the library.
Re:Kotlin Money on Tuesday October 08, 2024 @03:00PM (#41780593)
Thanks for commenting! I'm still learning Kotlin and I overlooked the usage of get() with vals. This will be the next syntactic sugar into the mix. I think it makes sense.

When I was designing the API, I created methods like toUSD() and toEUR(). But with 306+ circulating/tender currencies and 2000+ cryptocurrencies, I thought it could lead to a bad experience when using code completion.

Re:Kotlin Money on Tuesday October 08, 2024 @02:58PM (#41780571)
Great reference, Sam. I will definitely bookmark your library and learn with your implementation.

For cryptocurrency data, take a look at the DTIF.org dataset: https://github.com/eriksencosta/money/blob/trunk/docs/append...

Re:Kotlin Money on Tuesday October 08, 2024 @02:52PM (#41780513)
You don't need if your solution fits your use case. The library is an implementation of Fowler's Money pattern: https://martinfowler.com/eaaCatalog/money.html
Re:Kotlin Money on Tuesday October 08, 2024 @02:51PM (#41780505)
Thanks for commenting. I'm still learning Kotlin and I overlooked the usage of get() with vals. This will be the next syntactic sugar into the mix. I think it makes sense.

When I was designing the API, I created methods like toUSD() and toEUR(). But with 306+ circulating/tender currencies and 2000+ cryptocurrencies, I thought it could lead to a bad experience when using code completion.

Re:Kotlin Money on Tuesday October 08, 2024 @02:43PM (#41780432)
The library will throw an exception if doing an operation with different currencies: https://github.com/eriksencosta/money/blob/trunk/money/src/t...

But I think I'll make it explicit in the documentation. Thanks for pointing out!

Re:Kotlin Money on Tuesday October 08, 2024 @02:41PM (#41780421)
I'll introduce l10n support in a future release. My starting point was to make currency names and symbols unaware of the locale as I embedded cryptocurrency data in the mix.

Anyway, the library uses the CLDR dataset through ICU: https://github.com/eriksencosta/money/blob/trunk/docs/append...

Re:Kotlin Money on Tuesday October 08, 2024 @02:34PM (#41780359)
Languages indeed have support for currencies and decimal numbers. My implementation is based on Fowler's Money pattern. The Money object is thus a value object representing a monetary amount in a given currency.

https://martinfowler.com/eaaCatalog/money.html

Re:Kotlin Money on Tuesday October 08, 2024 @02:32PM (#41780346)
You are right. Languages indeed have support for currencies and decimal numbers. My implementation is based on Fowler's Money pattern. The Money object is thus a value object representing a monetary amount in a given currency.
Re:Kotlin Money on Tuesday October 08, 2024 @02:28PM (#41780299)
This is great!
Re:Kotlin Money on Tuesday October 08, 2024 @02:27PM (#41780290)
Joda is impressive and has great performance.

The examples were written using the infix notation but you can just use regular method calls. For example:

val price = Money.of(100, "USD")

val shipping = Money.of(5, "USD")

val subtotal = price.plus(shipping)

val discount = Percentage.of(10)

val total = subtotal.decreaseBy(discount)

total.allocate(2)

total.allocate(60.percent(), 40.percent())

Re:Kotlin Money on Tuesday October 08, 2024 @02:23PM (#41780249)
Thanks for the questions. Answers:

1. You get an exception

2. You may specify the rounding rule: https://github.com/eriksencosta/money/blob/trunk/docs/usage/...

3. It has some parsing capabilities. The extra digit is kept, rounding is only applied when doing an operation with the Money object

4. Same as 2

Re:Kotlin Money on Tuesday October 08, 2024 @09:57AM (#41777441)
I think I will add a footnote on COBOL. COBOL is huge in Brazil, lot of insurance/financial companies are still using mainframes.
Re:Kotlin Money on Tuesday October 08, 2024 @09:45AM (#41777318)
This is something I am aware but there is no support for this rounding scheme at the moment.
Re:Kotlin Money on Tuesday October 08, 2024 @09:37AM (#41777237)
I couldn't agree more as someone who has been using more spreadsheets than actually coding in the last 10 years.
Re:Kotlin Money on Tuesday October 08, 2024 @09:34AM (#41777212)
In Brazil (where I worked) we used Kotlin + Ktor. In Europe, they are heavy Kotlin users.

References:

Brazil: https://blog.eriksen.com.br/en/platform-engineering-n26 Europe: https://medium.com/insiden26/engineering-at-n26-a-tour-of-ou...

Re:Kotlin Money on Tuesday October 08, 2024 @09:32AM (#41777201)
Oh sorry, that's a typo. Thanks for pointing out!
Re:Kotlin Money on Tuesday October 08, 2024 @09:32AM (#41777198)
It uses BigDecimal. My first goal with the library was to provide a well-designed API. So to keep it simple for myself, I relied on BigDecimal for the calculations.

Older »