-
Notifications
You must be signed in to change notification settings - Fork 1
Code Questions #19
Comments
also on a thread about code questions https://github.com/Code4HR/hrt-bus-text-my-bus/blob/master/app.js#L138 is this finding the midway distance between here and richmond? |
also i think the long lat point points to antarctica. I also got a key(?) http://stanzheng.com/public_key.txt so yay? |
Okay, here we go:
Because I love functional programming and prefer expressions over statements to the point where I would use ternary operators in excess to ensure type/value safety, despite legibility problems. In other languages, the same semantics doesn't have such an awkward syntax. Also, in this particular instance, it reduces code duplication and the need for a local variable. It's a disease. You can absolutely change it if you prefer.
Yes.
The coordinates actually do point to Richmond, the HRT bus API reverses latitude and longitude from what you'd normally expect.
Sweet! I'll have to add that when I get home tonight. 😺
\o/! |
upon first glance i thought the equivalent was if(help)
...
if(address)
...
if(stop)
...
else(error) but i was wrong and the evaluation is as if i was expected but in a ternary syntax so i dont think a rewrite is necessary. Its something new for my eyes. if(help)
else if (stop)
else if (address)
else (error) Second question is why is it distancing between here and richmond? i'm curious whats the logic between that.
|
I forgot the exact reason, but the whole purpose came from trying to find the closest stop, and so I chose Richmond as an extrema in the fold operation. |
this regular expression is scary https://github.com/Code4HR/hrt-bus-text-my-bus/blob/master/app.js#L79 |
so i wrote the test "Should not fail on 150 Granby St" and it fails! mm i probably have to stub that out and find out why that particular POI fails. any ideas? |
i also feel if i write against stop numbers, if those stops or routes change the tests break.. but that could be good? i dunno false positives. what is a reliable way to test? |
Well, it sounds like you want to test live data, so you'd use a functional test for sure, so I would choose a stop which would have a small likelihood of actually changing or going away. Other than that, I have no real good suggestions. EDIT: Oh wait... you'd write tests for both stop numbers and addresses, no matter what. Same suggestion above applies, without further knowledge of how to improve those kinds of tests. |
Also, I'm absolutely aware that that regular expression will terrify anyone who observes it. I had no other immediate way of how to determine whether the citizen entered a stop, address, or garbage, and I want to try and adhere to LANGSEC (this speech got me into the concept) for these particular kinds of situations. |
Hairy regexs are AWESOME and I hate them. On Wed, Dec 17, 2014 at 10:49 PM, Ryan Y. [email protected] wrote:
Kevin Curry 3Scape begins @ http://3Scape.me |
👍 |
Hairy Regex do things like this address="150 Granby"
/^\s*(\d*)\s*(([a-z]+[.]?|\d*(1st|[23]n?d|[4-9]th))\s*)+(([a-z]+[.]?)\s*,?)?\s*(([a-z]*\s*)*,?)?\s*(V(irgini)?a)?\s*$/i.test(address)
>true
address="150 Granby Norfolk Va 23507"
/^\s*(\d*)\s*(([a-z]+[.]?|\d*(1st|[23]n?d|[4-9]th))\s*)+(([a-z]+[.]?)\s*,?)?\s*(([a-z]*\s*)*,?)?\s*(V(irgini)?a)?\s*$/i.test(address)
>false |
This is good code but is a bit hard to read.
Any reason why ternary operators instead of if/else or a switch case in this instance?
@ryayak1460
https://github.com/Code4HR/hrt-bus-text-my-bus/blob/master/app.js#L36-L55
The text was updated successfully, but these errors were encountered: