Skip to main content
24 events
when toggle format what by license comment
Oct 24, 2014 at 12:26 comment added Daniel R Hicks I disagree with your base statement in some circumstances. If you have data that is referenced from various places, some needing one format and some another, it's dangerous to keep multiple copies in the different formats. Better to keep one copy and convert as needed, unless the conversions are exceptionally expensive and frequent.
Oct 24, 2014 at 11:50 comment added Maurycy @KilianFoth I thought there was also the step of modyfing a variable in the question, I was wrong.
Oct 24, 2014 at 11:47 comment added Kilian Foth @MaurycyZarzycki Well, then it's not converting back - it's converting a different number to a different string. There's no way around converting again, so go ahead and do it. The prohibition against unnecessary code doesn't apply because in this scenario, it's actually necessary.
Oct 24, 2014 at 11:17 comment added Maurycy Converting from integer to string and then back to integer does not make sense, but the other way? If the user inputs a number as a string and you want to perform some operations on it and then display it back to the user, how are you supposed to do it without back-and-forth conversion?
Oct 24, 2014 at 2:36 vote accept user13107
Oct 23, 2014 at 21:31 comment added Jesan Fafon @DanielRHicks I agree. Any non-trivial system that a programmer is not at least slightly afraid of is a system they don't know they don't understand.
Oct 23, 2014 at 16:30 comment added Daniel R Hicks Well, maybe it's just a sign of experience. I've got 45 years of programming experience, and I've seen a lot of software that was so complex I was afraid to touch it.
Oct 23, 2014 at 15:12 comment added back2dos @DanielRHicks: I think it should be pretty clear I was talking about the answer and nothing else, which should also make it clear who I was talking to. My point was that if your system's complexity causes you anxiety, it's not a sign of humility, but one of bad design (and actually lack of humility). Programming is hard enough without trying to be smart ;)
Oct 23, 2014 at 15:10 comment added Doval @DanielRHicks You can use outside forces to justify any position. My point is that it doesn't matter how complex the right way of doing things is if someone already solved that problem and it's known to work.
Oct 23, 2014 at 14:58 comment added Daniel R Hicks @Doval - Very often your tool options are limited by outside forces, and it's pretty easy in practically any environment to end up with mutually incompatible libraries, if you aren't extremely selective when picking them. Not to mention the wisdom of adding a 100K library to a phone app to avoid coding a dozen lines doing a conversion directly.
Oct 23, 2014 at 14:54 comment added Doval @DanielRHicks If you can't get your project to build, get better libraries or a better tool chain. The only good excuse to reinvent the wheel is as a learning exercise.
Oct 23, 2014 at 14:52 comment added Daniel R Hicks @back2dos - Not sure who you're talking to, but complexity is the key. Sometimes doing things the "stupid" way is far less complex, and far easier to understand and "check". Far too many programmers take delight in building complex code, and as a result produce code neither they nor anyone else understand. (And using all sorts of obscure functions to do things that could be done in a much more straight-forward fashion is a primary source of complexity.)
Oct 23, 2014 at 14:45 comment added back2dos Nice answer. The last sentence though is terribly wrong. If you have that anxiety, then you're completely on the wrong track and badly need to reduce the complexity of your system.
Oct 23, 2014 at 14:45 comment added Daniel R Hicks @Doval - So you add 20 different "libraries" to handle 20 different conversion problems, then wonder why you can never get your project to build.
Oct 23, 2014 at 14:21 comment added Katana314 @PieterB There are so many ways in which date / time conversions can seem simple in your head, and then get agonizingly complex in code. For instance, "I'll just represent this date, no time, as an agnostic 'ms since 1970' value". Great. So that's midnight...WHERE, on the planet? It's definitely solvable, you just can't really underestimate it.
Oct 23, 2014 at 12:56 comment added Pieter B @CodesInChaos yup, that's why I want my code to be locale agnostic and only when showing output to a screen will I apply it. But I think that's another discussion because you could write books on that subject.
Oct 23, 2014 at 12:38 comment added Doval @DanielRHicks Any kind of complex conversion is almost always a solved problem - find a library that does it for you. Converting something to a different format and back carries the risk that the conversion isn't lossless or commutative and in the worst case is a waste of CPU time and memory that can be solved easily. Moreover, you need both the operation and its inverse. If you simply don't throw away the original data you can't screw up the original, you don't need the inverse operation, and it still works when there is no inverse (e.g. the conversion is lossy).
Oct 23, 2014 at 12:28 comment added CodesInChaos @PieterB There is a big German accounting software that doesn't work on computers with a non German locale because it does this. It first converts the date to string using the system locale and then tries to parse it with a fixed locale and complains about the illegal format. It does the same with numbers and varying decimal separators, except that it doesn't complain there, it corrupts the data and exhibits weird behaviour. Took me days to figure that one out.
Oct 23, 2014 at 12:11 comment added Pieter B @DanielRHicks so let's convert that simple date(10 november 2014) to a string, ->10-11-2014 and back to a date ->(11 oktober 2014) hey wait what?
Oct 23, 2014 at 12:09 comment added Robbie Dee Couldn't agree more. Otherwise known as The Single Source Of Truth...
Oct 23, 2014 at 12:06 comment added Daniel R Hicks But doing a couple of simple operations (convert to string and back) may be much less complex (easier to understand and code) than the "right" way of manipulating the bits. And keeping all data of a category in a single form is often a good idea, even if certain datum will be inevitably converted to other forms.
Oct 23, 2014 at 11:31 comment added Benjamin Gruenbaum "code that doesn't exist cannot have subtle defects, while code that exists often does" wish I could +2 you for that. Never underestimate the value of not having to write code.
Oct 23, 2014 at 8:51 comment added Neil Well said. We programmers should all be so cautious.
Oct 23, 2014 at 8:43 history answered Kilian Foth CC BY-SA 3.0