You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I learned that Go's "=" is not good enough for asserting equality of nested objects when writing tests. This was disappointing because it meant I needed to
4
+
use a third party library.
5
+
I learned that you need to be careful about using ":=" in a loop if it shadows an outer variable. I lost a couple of hours to trying to debug this
6
+
7
+
P.s I skimmed through the official implementation and it feels like I could do a better job (Is it hard to follow or it is just me?)
8
+
Plus lots of state. My implementation probably suffers from using recursion though
9
+
10
+
11
+
### Random thoughts
12
+
Not use recursion? - is that possible?
13
+
14
+
After looking at the code, I realize that instead of passing (s, current) into virtually every function, I could create a scanner type
15
+
and have these functions be methods in this type.
16
+
```golang
17
+
typeScannerstruct{
18
+
s string
19
+
current int
20
+
}
21
+
22
+
func(s *Scanner) consumeWhiteSpace(){
23
+
24
+
}
25
+
26
+
func(s *Scanner) isMappingStart(){
27
+
28
+
}
29
+
30
+
func(s *scanner) isMappingEnd(){
31
+
32
+
}
33
+
```
34
+
Other thing is to introduce the concept of tokens - only needed for strings? Since that's where you can have escaped characters!
35
+
36
+
So initially, I introduced the concept of scanners but then I realized that it didn't fit completely.
37
+
So I discovered the concept that was missing was the concept of iterators. A iterator is simply - struct{s string, offset int}
38
+
And this made other stuff make sense since I moved the stuff that didn't make sense in the iterator to standalone functions that instead of (s, current)
39
+
made use of the iterator. The other interesting thing is that I violated Command Query Responsibility Segregation (CQRS) and it was the right decision.
0 commit comments