Looking up stock price graph in Terminal
Ever thought about browsing stock quotes in terminal? There was two nice posts on hackers news last month that fitted nicely together that enabled this. It also helped me learn more about coding in Go, which I must admit is pretty cool to learn, but not without its quirk.
Screen shots first:
Wide version:
Narrow version (termui auto scaling):
Take aways after writing this:
- With a typed language, it is easier to access elements inside a struct with accessor function, not Pluck (in Go's case, it's Reflect)
- Strict variable checking and module checking sometimes is a little annoying. By commenting out one line that consumes a variable, you will have to comment out the definition (if there is no other place that use this variable), and comments out the imports
- "go fmt" is nice to have, but don't run it too often as it slows you down
- I still don't know how to create an array using variable as size. From pointer perspective it makes sense. Just use append
- NewList is such a strange syntax. You have no way telling whether you are calling a plain function or creating a object by simply looking at the function name.
- what happened on January 2nd, 2006 at 3pm? why formatting a time requires me to remember this specific date? I rather remember one more person's birthday.
- var variable Int doesn't seemed to be needed in most use case. := is better. Though it increases the amount of documentation look up
- if you return an err object, you are forcing the caller to write some err handling code. Doesn't this lead to error handling everywhere?
Thanks for two hackers news community posts (links below) for providing inspiration.
termui (github) HN: https://news.ycombinator.com/item?id=9276188
yquotes (github) HN: https://news.ycombinator.com/item?id=9374373
Code on Gist: https://gist.github.com/63404185ba39fae9d254.git