Maybe you could look up the Try monad API (Scala or Vavr works in Java + Kotlin), by using some extra helper methods you can have something probably a little bit lighter to use.
I believe your example would look like the following with the Try monad (in Java):
The login() function would be using the same pattern to call authService.verify() then filtering nonNull and signing the JWT, so it would be the same pattern for both.
It's no accident that Rust's bootstrap compiler was written in OCaml. Rust borrows a lot of ideas from it. Arguably, OCaml and ML are closer ancestors of the language than C.
I like Rust, I use it as much as I can. But, it actually doesn't bring many new features to the table. What it's done is successfully learn from the past, scooping up the good ideas and ditching the bad ones. Its real selling point is how it wraps all of those old ideas up into a modern, well-maintained, stable package that's ready for use in the real world.
> What it's done is successfully learn from the past, scooping up the good ideas and ditching the bad ones. Its real selling point is how it wraps all of those old ideas up into a modern, well-maintained, stable package that's ready for use in the real world.
Which is no small feat. I wish OCaml cleaned house and settled on just one stdlib and removed a lot of legacy baggage, and oh yeah, add built-in Unicode support, and 5-6 other things I am forgetting now.
Sure you can muscle through all that but having Rust around really makes you wonder if it's worth it and in my case I ultimately arrived at "nope, it is not" so I just use Elixir, Golang and Rust.
To be fair, many languages have their bootstrapper written in OCaml or another similar ML. When I took my programming language interpreters and compilers classes, that's what they mentioned to us, because they are uniquely good at writing recursive descent parsers.
I have been solving these since years, I find it a nice way of assessing a language and deep dive since it will cover lot of parts of what makes a language.
I have been porting my old solutions in other languages into Kotlin over the time, and will be again doing them in Kotlin. I find it a nice language for AOC since custom extensions and DSL possibilities, it has a good builtin libraries and you can always fallback on Java, even if it has some shortcomings.
Regarding the AOC per se, I take it as a fun daily challenge, I know I won't be able to be part of the top 100, at least I would with some luck during the first 3 days, and then.. nope, that's life, try not to be too competitive. Last year it took me 8 hours to solve day 20, but it's a game, you should have fun doing it (I had), if not people should stop.
However, I strive in trying to write pretty, compact, idiomatic and as functional as possible code, which means that sometimes I will write an ugly solution in 5 minutes, and will take an hour to make it beautiful.
Besides I like to read the story, I know plenty of friends who don't even read the adventures of Santa, they just solve the puzzle and that's it, they don't even know they saved Christmas :-D !
> which means that sometimes I will write an ugly solution in 5 minutes, and will take an hour to make it beautiful.
I think I spent 2 hours last night just playing around with different methods of solving it after my initial version. Other libraries, slightly altered algorithms. I think that's one of the parts I enjoy the most, solving the puzzles is fun. Trying a dozen different variations is, for me, more fun (and more edifying).
Yeah, kotlins stdlib for collections is great. Has all kinds of variants of reducing, grouping, filtering, mapping, taking, dropping etc one can think of. Today's solution was to just call the window function.
2020's day 20 was really tricky - that, and day 23 were the only two days I didn't manage to solve two parts on. I managed to get part one for day 20, but neither parts for day 23. It was good fun trying both, though!
Or not trimming your input. I worked and reworked and reworked a problem once, the answer was some number in the billions. Eventually I gave up because I just couldn't work out where I went wrong. I then took someone's working solution and plugged my input in, and I was out by one, because it counted chars and I had a stray newline.
I'd like to say it only happened once, but, it happened again later that year... And then never again (because I pulled out code to always strip newlines after reading it in ;)
Good reading! I did learn a lot regarding tools I didn't knew and I will definitely check Reedsy and Scrivener, I did use leanpub which was really good, doing almost everything for me.
The hardest part is about marketing for me, and I am happy that I first wrote the book for me and see the completion as an achievement, I talked with a lot of people who thought it was kind of easy to get rich just writing books, I don't think so, not easily.
Also, it's really tough to promote a book without feeling like you're over-trying to do it, and regarding an IT book, except for a reddit community, or twitter I wouldn't know where to start.
I have even been invited to online conferences, people seemed to be interested (don't think they were faking it), but it generated zero sales :)
I really like Scrivener for putting together a book from scratch. The downside is that it's mostly a "just you" tool. Once you get into collaboration/outside editing/etc. I find you need to switch to something else. IMO, it's still worth it but I find it's something I use to get to a rough/first draft and then I switch.
Scrivener is the bomb. If it had vim bindings I'd be in heaven. And it's nice to support a small company making a product entirely focused on just being GOOD.
For me, the best way is just to start writing it. I've written a book about a Java library last year named "Practical Vavr" [1], I had the idea since some weeks/months and with the COVID situation having time at home, just told to myself now is the time.
Didn't thought a lot about anything, except for how the book should be laid out, I thought the process was interesting so I went full on it, discovered leanpub and other websites that makes the process easy as just writing some Markdown.
I think that the hardest thing is the marketing around the book, how to tell the world you wrote it and why they should be interested in reading it (and buying it). I just posted it here and there on the web (reddit, twitter mainly), didn't made a lot of fuss about it, I don't know how anyway.
In the end it was more about the experience of writing one and finishing it, than making big money (even if I was able to reach almost 100 people totally unknown people who were kind enough to trust that the content would be good and buy it).
I have written a couple of technical books and what works for me is to blog about it. This would be the step after the outline step in the article.
If I can't write 10 or so blog posts on the topic, can I really commit to a full book? For me, the answer is no. There's a lot of grinding in writing a book, so you'll need intrinsic enthusiasm on the topic to finish.
Leanpub is a nice way to get feedback as well (there's nothing that indicates commitment like $$), but writing blog posts (and sharing them on places like HN or a forum about the technology) can get you feedback.
Thanks for the feedback of the article! I appreciated it :- )
Writing a technical book is a nice experience if you feel confident. If you have the passion and dedication to write, it'll be a journey with the "side-effect" of earning exposure and if you're lucky, also money. But you should not write a technical book for money (set as the first goal).
Marketing a book, especially a technical one, is difficult and requires time. Since most of the times it's suitable for a niche, you have to look for people and to explain why reading your book would be worth it. Does it contain any special feature that makes it unique? A particular focus? A well-written introduction?
I'd like to discuss about the points you marked. "The best way to start a book is writing". When you have the inspiration of writing, it seems "you do not have to think too much about details, a possible outline". It's partially correct and wrong. On one hand, to publish a book, you need content and what's the best way to create content? Yes, it's writing! On the other hand, people are not looking at your book for "content", BUT for highly quality content. Thus, not only you have to write the content, you have also to think about the structure, the outline, the key-points, and many others element that keeps the reader "on" your book.
Maybe you could look up the Try monad API (Scala or Vavr works in Java + Kotlin), by using some extra helper methods you can have something probably a little bit lighter to use.
I believe your example would look like the following with the Try monad (in Java):
The login() function would be using the same pattern to call authService.verify() then filtering nonNull and signing the JWT, so it would be the same pattern for both.