A Survey of Surprisingly Difficult Things

Video in TIB AV-Portal: A Survey of Surprisingly Difficult Things

Formal Metadata

A Survey of Surprisingly Difficult Things
Title of Series
Part Number
Number of Parts
CC Attribution - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this license.
Release Date

Content Metadata

Subject Area
Many seemingly simple "real-world" things end up being much more complicated than anticipated, especially if it's a developer's first time dealing with that particular thing. Classic examples include money and currency, time, addresses, human names, and so on. We will survey a number of these common areas and the state of best practices, or lack thereof, for handling them in Rails.
Aliasing Trail Scheduling (computing) Implementation Link (knot theory) Real number Multiplication sign Archaeological field survey Similarity (geometry) Mereology 2 (number) Fraction (mathematics) Mathematics Goodness of fit Roundness (object) Causality Different (Kate Ryan album) Term (mathematics) Daylight saving time Representation (politics) Energy level Integer Endliche Modelltheorie Address space Physical system Social class Area Time zone Standard deviation Software developer Projective plane Shared memory Electronic mailing list Physicalism Database Line (geometry) Timestamp Entire function Stopping time Tangent Cache (computing) Type theory Computer animation Ring (mathematics) Doubling the cube Video game Right angle Musical ensemble
Trail Time zone Dialect Computer animation Mapping Multiplication sign Daylight saving time Rule of inference
Time zone Boss Corporation Default (computer science) Context awareness Computer animation Different (Kate Ryan album) Multiplication sign Range (statistics) Database Cartesian coordinate system
Point (geometry) Suite (music) Greatest element Context awareness Group action Service (economics) State of matter Code Multiplication sign View (database) Execution unit Event horizon 2 (number) Programmer (hardware) Rekursiv aufzählbare Menge Mathematics Different (Kate Ryan album) Robotics Term (mathematics) Natural number String (computer science) Endliche Modelltheorie Physical system Social class Area Time zone Default (computer science) Data storage device Database Line (geometry) Cartesian coordinate system System call Process (computing) Computer animation Personal digital assistant Blog Statement (computer science) Gravitation Right angle
Programming paradigm Service (economics) Validity (statistics) Code Execution unit Data storage device Physicalism Plastikkarte Bit Line (geometry) Number Computer animation Family Bounded variation Speicheradresse Address space Physical system
State of matter Code Multiplication sign 1 (number) Code Product (business) Revision control Bit rate Boundary value problem Damping Endliche Modelltheorie Office suite Address space Scripting language Validity (statistics) Information Digitizing Data storage device Database Bit Entire function Human migration Word Process (computing) Computer animation Quicksort Object (grammar) Routing Speicheradresse Library (computing)
Code Multiplication sign Client (computing) Coma Berenices Mereology Magnetic stripe card Formal language Web 2.0 Medical imaging Round-off error Mathematics Formal verification Electronic visual display Endliche Modelltheorie Internationalization and localization Physical system Email Infinity Instance (computer science) Entire function Internet service provider Configuration space Right angle Speicheradresse Resultant Domain name Server (computing) Service (economics) Process capability index Web browser Login Event horizon Rule of inference Number Product (business) String (computer science) Software testing Address space Computer architecture Domain name Key (cryptography) Information Validity (statistics) Planning Plastikkarte Total S.A. Multilateration Cartesian coordinate system System call Shareware Computer animation Personal digital assistant Local ring
Slide rule Computer animation Ring (mathematics) Personal digital assistant Squeeze theorem Product (business)
this is the end kind of human and the all right let's get started I I can see very well out there so I'll show you that you feel the need to as questions if I'm has a conference for everywhere so far good the excellent right this thing's not work that way so this I'm not Alex I work for have folio which is a company in Santa Barbara I work in the San Diego Engineering Office and we're hiring and talk to me and so I the last I would have said 1 particular project inspired the style but really it's also the culmination of you know the kind of experience you get after a few years of doing was developed this is a survey of surprisingly difficult things now what things do I mean mean commonplace things that you know all about in your day-to-day life so they're easy to model and you model them and the great and then it turns out it's actually a lot of that and so things really obvious implementation may very well cause problems and in fact you know I these are things like timestamps time zones physical addresses human names now when you hear these these terms when you think to the Saudis these solve problems right easy no problem no complications but when I'm not gonna talk about I'm not gonna talk about cache invalidation or distributed systems or other also surprisingly difficult things but is about real world stuff the so 1 of the things you know 1 of the rings I want to give this talk was that developers following these traps all the time we spent months cleaning up whole-body code of and then new bonds of the same type introduced 6 months later by other developers so maybe you know with a laundry list of things to be aware watch out for and he will fall into that trap Penny even very senior developers you know it might help to just have the occasional reminder here if you notice you develop a new heaven dealt with this stuff much before and hopefully this talk will save you sometime in the future the and another good thing is that if you follow these best practices or similar things you then hereafter be more inclusive the the so you can I know that when I started dealing with with the fact this role of things I you know cause wondering it my just drive you to drink too so would stop time so there are a bunch of time and date of classes available to you are the only 1 I really wanna draw attention this is mostly for reference later but what I wanted right and to do the last line where there's just no good Cross System standard for duration it's different in every database it's different in Ruby of that is in the database is so pay little attention of that and check on active support duration but what makes time actually hard to deal with is not this its tangent so again is in this to solve problem you can just have a sufficiently large integer r to represent seconds or fractions of a 2nd and now you have a time value and you're dead right no problems with but will the again the problem is in times and so how many time zones do you think there are the anyone 30 something then the 40 the yeah but but we you may be right below that that that at a certain level so only the at the time zone database which I'll talk about a minute defines 385 time zones and then has a further 176 internal links which are aliases basically be given different names I'm so something to remember their half hour time zones the the quarter hour time zones you get daylight savings time to take into account daylight savings time they start a place they start observing daylight savings time the previously didn't like Arizona currently doesn't of a place they change the schedule like the entire United States didn't a 10 years ago or so and shifted when daylight savings time started I I don't know if this is true currently that certainly in the past we've seen examples of two-hour daylight savings time changes this was called double summertime in UK are in a place they change time zones entirely maybe just switch so this times a database I spoke of is used in many Unix-like systems it's use all over the place armed with a small band of dedicated developers on the tracks all geographic time zones since 1970 they define an area as you know where any 2 places share evidence same times at the same share the same time at the same time so not before seriously hit that before 1970 they don't care as much but they do have historical data in it but it does track daylight savings time changes so an example of this is updated several times a year if you think this stuff is static no credit is updated several times a year and here's an example of some release notes the you can read through that quickly Mongolia no longer observes daylight savings time this region move from 1 to another year round and the clocks starting at this particular time I've got a new area which also affects part of an article it this change fixed many entries for historical Siam for of Madrid before 1979 and um it noted that Ecuador
switched actually observe daylight-saving time to so the the exact details are reported just know this stuff is really complicated and I think it is somebody's keeping track of it I'm and that's an example of all the actual regions defined that's again just unique regions since 1970 what another will trivia you know how many time zones in the United States according to this map just the continental United States I can at least 6 so we use
UTC as a way to standardize things you know when things happen at the same instant in time regardless of what we're actually call that time in a particular place hopefully we know that stands for neither Coordinated Universal Time nor Thompson of the so called today time name by diplomats UTC is not a times and every comes and has an offset from UTC 1 and as a rule you should store your time values in UTC so also also before I proceed how many what are the possible offsets from UTC UTC's kind and middle in go forward from it in the back how far do you do they go anyway wanna take a guess well that is exactly what I thought it so 1985 cure
boss got tired of having the country into different days so they move the time zone of some of the outlying islands so from minus 10 to plus 14 so there are plus 14 times ANS on that side so keep in mind without a time zone any time value you have without context How could take place within a 26 hour range possible half hour quarter hour increments the so how you
handle this well if you don't explicitly provide a time zone the 8 time you provide could be interpreted using the operating system's default using your databases default or using your application's default times on that should be configured in your Rails up the OK now is
slightly bigger dying so as we said
keep your system and and database and time in UTC rails will store it state times in UTC and time zone aware methods in rails will use the application's default if you don't overwrite it with the by explicit expressly providing 1 the so for example if you have users we show story the time zone on the user's model and always use that in their in your views if you need if you care at all about when things occur for certain uses and just as an example here you can see that term where use time doesn't not now about this little more than minute and active support provides and it's really sophisticated stuff around it alone just you'd be every time he was the rails classes for all this stuff so these times aware of methods and you can see were passing 2 different times in different time zones with the actually the same time so it all works that's cool calm and here's some examples of some methods you should use this 1 hours from now days ago those are all good always time Paris don't do timed out pass on if you use a string past time in the middle here always used in time zone at the end or you will be screwed I am prefer definitely time that current to I have other methods forgetting the current time and the UTC ISO 86 0 1 is 4 if you're providing an API that much using to provide something to an API on is examples are all from a um so and shamelessly from a blog post that I know there on the bottom so data simpler right the it's don't have a time zone How do you know if you should be storing something In a data on time S. yourself doesn't matter what time of day this seems really basic but people think this mistake all the time and is converted I'm a day to a time willy-nilly I'm so don't do this so what are some examples days will birthdays a birthday occurs on a day we don't generally observed when the actual minute of the day the person was born on all the calendar events but maybe holidays you might think so for example I don't know you know I have to take a western example Christian Christmas that is on the 25th regardless of whether or not you're envisioning were Toronto or where so as I said don't store dates and times you will have problems be very leery of converting back and forth it almost never when do that I for example if you were the 1 case I can think of off hand is if you have a calendar that you've written and you want to convert it was editing event in it goes from being say an all-day event to a timed event then maybe so let's see where are we so this is fine that's PreDeCon from and so you wanna use day that current because I ran these 2 lines in the middle of the day of seconds from each other and that's what I got what happened but quite a debate that way anyway but it so they the yet basically currently takes into account your timezone below and is basically telling me that in London and so on the 24th but I see day died today all over the place and code on Sept is are really the only to date methods you should be using the you absolutely have to avoid and now kind of past time that string past time without the in times and things of the end or did that today so that I can help you with this is that should use robot who uses were up the avenues put that into your actual process formally a few good call I give like until a couple years ago on this and the pressing the few people did that so their services like hounded Farsi for others that I'm coder see that I'm not thinking of or not familiar with but you may get this a blocker so the UK merger P was a passenger style amongst the many benefits of that is that RoboCup watching catch some of these areas for you more comments questions about dates and times let's move on to human names so I many of you may have read there were a couple of blog posts that were related 1 was called falsehoods programmers believe about names to believes action inspired by false it's pretty clear about time and to take a few examples from this we have things like the none of these statements are true people have exactly 1 canonical full name you people have exactly 1 full name which they go by no people have at this point in time exactly 1 cannot fully people have at this point in time 1 full name which they go by no people's names do not change that's not true he was names change but only the suit certain enumerated set of events no people's names are assigned at birth not true people's names are written in as q absolutely not true I'm guessing in this room there's a bunch of people whose names are not actually written as although I'm guessing very few in just Imojean's yet that that'll that'll come book but he was entering any single character set that's natural people's names are all mapped in unit code code points that's not true 2 different systems containing data about the same person we use the same name for the person that's hopefully pretty obviously not true either there also now and feel the gravity and so really the only thing you can do here with names is valid as
little as possible just don't bother wire you try right I like you know yes the cardholder Name pro has to match when you submit credit card but that's their problem you know I if you can avoid 1st name last name consider doing so just useful and yeah I have no idea what's going on and but and you know maybe use given name family name to be a little bit less um English specific I'll also you know store things in unit code remember you can guarantee real names are used and don't assume just because you might have a US-based in the US centric business that your users will be primarily English-speaking or on even have as names that's you know these things her true in the US as well as overseas how can a physical addresses so how you model physical addresses tha are you right you in that's good well there are a lot more variations on this than you might expect even in just the united with United States Postal Service the so even the US remember their role routs that look like this the military addresses the look like that's that doesn't quite fit the city-state paradigm I remember useful service that services porta rico which has a very different at a structure and and you can actually have a surprising number of lines in a valid address I so 1 example that was supposedly ballad that had 12 lines long it was an international 1 but still and basically don't do this
so until I moved recently my address had slash it is actually pretty common in California have 1 halves in numbers it doesn't validate with Southwestern dozen validate with quite a few legacy systems that you'll see out there I have a bunch of a bunch of banks and things and things to apartment 1 half so you can
standardized these addresses via the US postal service the old belt convert them for you and give you some the right abbreviations are but remember that special characters are still allowed even after that node for example cities can have apostrophes in them Our addresses can have slashes or dashes and so forth things to know about US postal codes don't use just zip codes in general try to use the postal code which is the international version of the word and I don't just make it 5 characters longer 10 characters long if you wanted to do plus 9 because again you're excluding the ability to store addresses from other countries including Canada which is close enough you might actually wanna build a ship to it and and also as a bit of trivia remember that you can even use of codes to map to states there is a database you can buy or possibly the 1 for free that will attempt to give you see information that zip codes not only can cross city boundaries they can cross state boundaries and here the ones that currently cross state boundaries and that's all because codes mapped to postal routes not to geography it just so happens that most postal rocks geographically constrained so let's see what validate addresses again my 1st and the instinct is to say why you doing this but OK great the US Postal Service has a database of them however these are not always the same as the physical addresses there are entire towns and communities that have no physical addresses in the US Postal Service database for example I'm in San Diego 1 of the very wealthy suburb not suburbs it's actually separates the well the very wealthy cities the center say counties Rancho Santa Fe Postal Service delivers everything to their post office and that's set because they and what the postal trucks driving around going to people's houses yeah its UPS and FedEx will deliver to people's house where so a few shipping something maybe you should let them enter their home address even though it's not going to validate a the as any comments questions about her fun step of addresses here anyone pure alright money yeah the only to get paid right and had model money in your Rails apps database schemas but this that's a given a no correct what is a float I have seen that go any other possibilities that's a good 1 and a small so I've heard those 2 there is a sort of the other 2 I approaches and I'm familiar with so you may use as small values that's where migration doing that would look like good there are some issues with that now that it's invalid here we have let Ruby code that will allow render your product for your API will send this out because it's a decimal it'll look like that when rendered and now in JavaScript we do this what's wrong with that and so I the and will maybe I that anything else what in correcting ding ding these of floating-point occurred product price JavaScript is now naively it followed that's how the just the J son however you know works so you can well sorry after that
bond came of 3 different times do you can get around that and if you want to work always remember to use a decimal library on the job script side there's a problem with that but inevitably someone will forget to cast to making you decimal object and the but will be introduced also you'll get very strange rounding so when for example you're multiplying by saying tax rate or something like that it's maybe has 3 significant digits and then suddenly you'll have i tripoli rounding issues in your money wanted to I prefer the just or sense I
used to use images everywhere you won't have rounding errors I I recommend you keep you know the name ends in sense as part of that everywhere and then only convert at the last minute for display purposes 2 dollars or whatever your currency is to be where some currencies have Mills instead of sense so that's important just remember your multiply by thousand instead are and in this case usually it's obvious when you forgotten to convert because it's there on the display the totals will be wrong uses a test a e-mail addresses
those are easy right and yeah so this is now a valid e-mail address and just keep that in mind this is now a top-level domain there are still places out there that try to validate . com . net dot EDU and you can validate that the you know there's an act there has to be at sign in e-mail address there has to be 0 . somewhere the domain name that get otherwise you can do the whole verification e-mail that's right I which everybody to people people know this but again people still tried over validate and it's kind of like again why are you doing this the also just mention as a sidebar that for people are aware of this most by e-mail systems particularly Gmail our will allow you to add a + f u username will still get delivered to you but now you can have an infinite number of e-mail addresses without creating new users this is great for testing for for creating felt in free trials or whatever you need to do so right here nationalization I talked much about internationalization isn't huge topic there are literally the entire conferences on on I do have a suggestion which is that if particularly the evergreen Greenfield application just rails New start putting your you know hard-code strings in your configure locales just from the beginning even if you have no particular plans to and go international or support other languages a cool thing but call result of doing that is the 1 changing copier copies easier you have to search all over the place it's all in 1 place and furthermore you can even turn over the keys to like a product person or a non down and they can make the changes themselves directly In the code instead of payoff you then you just review the change of also if you had a locale to user model and always use it then again you won't have to back or or fill the stuff in later and you can't just start if you're in the US with USC and or whatever makes sense for you and and then it's there the hinting credit cards and the huge topic there's a lot to talk about read up on PCI compliance of again there is an entire industry around PCI compliance I thinking you know what most people know about it and what you need to take home is never story credit card information but don't even send it from your client browser to yourself use a service that will come but you said it directly from the client browser and then give you a web of back and that will unite even relying on the browser that you know somebody's using on an airplane with a cry know there on a Chromebook on an airplane just imagine that scenario and now you're relying on them getting the token and Sinead supporting that you know just use web server of and be sure to consider what happens if we call it to your provider stripe or whatever times out right that can happen and depending on your architecture if you don't use weapons you have to actually escalate timeouts to human being to go and look and see what really happened like did the call go through where did it fail some recurring calendar events to if that's easy right you just have like a day of the week and say you know when it when it recurs or something like that in your fine right now read this RFC and consider that most recurring events have no end date so your model that there's an infinite number of them and the rules can get pretty complex this is a fairly simple 1 like every month on the 2nd to last Thursday I had individual instances of a recurring event can be edited or moved the canceled separately from the actual recurring event and a year now I need this particular
body Mary yeah that that that that that the this case so to categorize in Seattle but I like to just point out that this particular 1 that has as a garnish a 2nd Bloody Mary really get the eye while you're working your way down to the Bloody Mary and in case you think onion rings chicken wings and a submarine sandwich a 12 inch pizza french fries and why were not enough here's the back you and there's a cheeseburger and onion Eliam a lemon and to real G. Sanchez but you might need this so if you start working on are highly recommended I so
talked a little fast rental early by in conclusion the main takeaways done over ballot people people just have this need to to quite check the values of these things when you can't and I don't understand that he even US only products will have global like problems be culturally aware remember that your experience is universal and probably isn't typical and just don't make assumptions and there are some references if you my slides later for the but a lot of satisfying here the what that
things needs