lmikolajczak/go-cli-chat

Project refactoring

Closed this issue · 3 comments

This simple app could be written in a much more clean manner and be more readable for anyone who tries to check it and understand what's going on.

Hi, thanks for writing this project. I found this from reddit thread. I am golang newbie and it help me learn how to use channel

I have question on part where disconnected client removed from the list. My question is if it is okay to mutate a list (remove items) while iterating it.

This is the reference that I read about the issue :
Removing item(s) from a slice, while iterating in Go

Hi @nuhamind2 !

I'm glad that this project helped you understand some topics in Go. As you can see in my first comment - this project needs some refactoring (I created it when I was actually learning Go and today I'd write some things completely different).

In regards to removing item(s) from slice while iterating - you're correct, I should not use range, because it can return index out of range error in this case. However for i := 0; i < len(slice); i++ syntax should fix the issue. If you want you can submit PR with the fix. I'll try to find some time to refresh this project but probably it won't be any time soon.

In the coming month(s) I plan to finally refactor this project, so expect this one to be solved and code itself to be better structured and more readable.