Changes 4/29/14
Ruby:
- Ran tests, fixed a nil error which was kind of confusing:
- In ruby, adding ! to some methods causes the function to apply itself to the object. For example, the statements:
- arr = ["a"]
arr.map! {|e| e.upcase}
- would cause arr to equal ["A"].
- I had a method returning the statement:
- fileargs.compact!
- Compact removes all nil values from an array, and the ! causes it to apply to fileargs. This normally worked fine, but since it was returning as well as applying the operatoin, some strange things happened. If fileargs was [], then for some reason the method would return nil, whereas normally it would return a compacted array. I fixed this by removing the !, since it is not necessary (and probably not correct).
- I have no idea why the method would only return nil in a very specific case, though. It probably has something to do with the differences between .compact and .compact!
- I also submitted a pull request for my code. Functionally, it's pretty cool now. You can pass something like grant 12 to parse all grants in the year 2012. You can even parse something like app 12-14 to parse all applications between January 1st 2012 and December 31st 2014
Javascript:
- Had a good discussion about proper data structure implementation in javascript applications, as one could store data in the html classes, a separate dataset or both.
- The best way is to have an underlying datastructure from which the html displayed to the user is generated.
Python has map as well, but I'm not sure I understand what ! does in this case.
ReplyDeleteIt applies the function to the variable. For example arr.map! ... is equivalent to arr = arr.map ...
DeleteAs far as I can tell it is more of a convenience than anything else.