Keskimaki / tiralabra

Lichess Chess Bot, Tiralabra 2023 kevät
0 stars 0 forks source link

Code Review 2 #2

Open sofiak-hel opened 1 year ago

sofiak-hel commented 1 year ago

Context

Some context that might be very relevant to understanding my review, is that I've actually worked with JavaScript using JSDoc and Typescript as helping tools, using Node.js professionally for years. This means I have quite a lot of experience with Javascript/Typescript and Node, but I might be making assumptions about pure typescript and Deno. I have looked into using Deno at work too instead of Node, but I'm not too familiar with it.

I also apologize that I do have quite a bit to say, but do keep in mind that I have formed somewhat strict mindsets about typescript in my years of coding and overall I think the codebase looks pretty good!

Documentation and first glance

Moving on to reading and reviewing the actual code

In conclusion

In conclusion I would say that at least in a quick glance this codebase seems pretty alright, although there are quite a few changes (at least in semantics) that I would personally make. Good job on this project, the program is certainly fun to watch as it goes, and good luck going forward!

Keskimaki commented 1 year ago

Thank you for a very comprehensive review!

Better explanation about setting up a Lichess bot account is probably in order. The current experience of starting a game and there being no indication about the game ending are certainly not ideal and something I would like to improve. I intended for the bot to be capable of automatically accepting challenges as well, but the implementation of the more specific chess rules like castling, en passant etc. took longer than I expected.

Multithreading is something that I didn't even think about, but would make a lot of sense as a future improvement.

I come from a mostly JavaScript/Node-background and wanted to experiment with new, but also somewhat familiar technologies with this project. Deno differs from Node in having a native TypeScript support so there is no need for a separate tsconfig.json, unless you want to override some of Deno's mostly sensible defaults. For example noImplicitAny is enabled by default and I have simply overriden the rule in a few places. This was done mostly for speed of development.

Having .ts at the end of imports is the correct convention in Deno, although it feels somewhat wrong for me as well. Deno has inbuilt linting and formatting tools which replace the more typical ESLint and Prettier setups in Node.

I agree with the suggestions on typing. The current types are a bit of a mess as I lack experience with TypeScript and initially used the chess.js library for most of the game logic. The Lichess API requires using UCI notation, but I would otherwise have only used array indexes instead of a mix of them and UCI board positions.

The double definitions are an unfortunate end result of me not being sure what kind of documentation is expected for the project. I typically go with the also not ideal "the code is the documentation"-approach so I might have gone overboard with pointless comments this time.

When it comes to arrow functions, I personally feel like it's simpler to just use the same function notation for both regular and lambda functions etc. but using the function keyword for regular functions is probably the more widespread opinion.