|
bignumber is an example of the kind of library that would be useful. BigDecimal, derived from IBM code, is another. But really, calculating in cents and optimizing the order of calculations should beat either one. e: Unless you're doing compound interest calculations and then holy moly you really need to talk with an accountant. Gazpacho fucked around with this message at 01:57 on Feb 10, 2013 |
# ? Feb 9, 2013 23:37 |
|
|
# ? May 16, 2024 23:23 |
|
Tei posted:Well.. yes.. is money. People don't like wen money is lost. I can't say for sure, but I have this feeling, a hunch, that unless you're dealing with bank-like volumes of money, floats are fine. A POS terminal would probably be fine. I'm imagining a situation where a customer with an overflowing shopping cart and even still a single transaction would probably be fewer than 1000 items and the money involved would be less than 10000. At the end of the transaction, round the result to 2 decimals and I'm pretty sure that your calculations would be correct. This whole floats-are-too-inaccurate-for-money honestly sounds like one of those programming-related legends that are not applicable to over 99% of use cases.
|
# ? Feb 10, 2013 00:48 |
|
I have no idea why anyone would need sub-cent precision for a POS terminal. Does anyone actually care that they end up paying $15/item instead of $14.995 when they get nominally 50% off?
|
# ? Feb 10, 2013 01:41 |
|
Jabor posted:I have no idea why anyone would need sub-cent precision for a POS terminal. Does anyone actually care that they end up paying $15/item instead of $14.995 when they get nominally 50% off?
|
# ? Feb 10, 2013 06:54 |
|
Jabor posted:I have no idea why anyone would need sub-cent precision for a POS terminal. Does anyone actually care that they end up paying $15/item instead of $14.995 when they get nominally 50% off? Also depending on how you process refunds (whether it's based on final invoice price or recalculated based on number of stock purchased, price and discounts, which is fairly common in wholesale though rare in retail) you could make people mad that they can't match their $14.9995 refund to their original $15 invoice. It's super minor but if it can be avoided there's no reason to not get it as accurate as the rest of your system.
|
# ? Feb 10, 2013 11:58 |
|
Also don't store currency in a back-end system in anything other than an extensible decimal format, because you'll be screwed if the precision requirements change. Tei it's really hard to give you abstract advice without knowing anything about your requirements. You'll be using floating-point arithmetic either way (binary or decimal) so you should learn how it works, and not treat it as magic. And again, if you are going to deal with real money, have an accountant review your calculation methods.
|
# ? Feb 11, 2013 01:13 |
|
Can someone in the know kindly summarize what's going on with all of the JS MVC frameworks that have sprouted in the past couple of years? Angular, Ember, Knockout, Backbone etc.. why does the world need so many and which ones should I be following?
|
# ? Feb 11, 2013 12:47 |
|
DreadCthulhu posted:Can someone in the know kindly summarize what's going on with all of the JS MVC frameworks that have sprouted in the past couple of years? Angular, Ember, Knockout, Backbone etc.. why does the world need so many and which ones should I be following? Say you want to do MVC. You have your model classes (where your data is.) You have your view - the thing that presents your data. Your problem is that without a framework, you need to figure out yourself how to get your view to reflect the content of your model. You can do this yourself but it's boring and sucks rear end. With a framework like knockout JS, you get stuff like * Declarative Bindings - easily associate DOM elements with model data. * Automatic UI refresh - when the data in your model changes, the UI will automatically update itself to reflect the state of the model for free. So you get the ability to just annotate an HTML file with a tag indicating that the html element (like an item dropdown) is part of your model, and the framework will update the content of the dropdown accordingly, and change the values in the model when the value changes in the UI. Regarding which framework is best, I have no idea because I am a C++ developer and know very little about front end development. Just pick the one that's least annoying - I liked knockout for what it's worth, but I bet people hate it because microsoft likes it.
|
# ? Feb 11, 2013 23:17 |
You guys should check out meteor if you haven't already, it's pretty cool.
|
|
# ? Feb 11, 2013 23:31 |
|
Thanks for the clarification. Are any of those frameworks particularly friendly to highly relational and hierarchical data? Say I'm writing the admin dashboard for an analytics service, and so I end up fetching a lot of data across tables (pre-empting the NoSQL suggestion, yes it's something I'm thinking about), joining it and and doing some light processing of it in before displaying it (yes, this should be eventually done server side, but at this early piloting stage it's ok). Backbone sucked balls for this and I ended up having to basically do a manual two step of "fetch all of the data I might need", one table at a time, with Parse's promises. Once the data is available, I process it and dump the results into the DOM. Using Backbone views and models for linking 3-4 tables together looked significantly harder than doing it by hand "the dumb way". DreadCthulhu fucked around with this message at 01:17 on Feb 12, 2013 |
# ? Feb 12, 2013 01:01 |
|
DreadCthulhu posted:Using Backbone views and models for linking 3-4 tables together looked significantly harder than doing it by hand "the dumb way".
|
# ? Feb 12, 2013 02:49 |
|
DreadCthulhu posted:Can someone in the know kindly summarize what's going on with all of the JS MVC frameworks that have sprouted in the past couple of years? Angular, Ember, Knockout, Backbone etc.. why does the world need so many and which ones should I be following? This seemed like a pretty good summary to me: http://blog.stevensanderson.com/2012/08/01/rich-javascript-applications-the-seven-frameworks-throne-of-js-2012/ Personally I have been playing around a little with Angular and so far I'm kind of liking it. Not so bare-bones (heh get it) as backbone but ones like Meteor seem to go a bit too far.
|
# ? Feb 12, 2013 21:13 |
|
I'm doing a "Robo-speak convertor" as an assignment in JS and I have most of the logic down, but something is failing in one place or another and I'm not sure why. It's supposed to be a menu where you enter 1, 2, 3 or "exit" in a text box and click submit, and each of these commands does a specific thing. 1 prompts you to enter the string to be converted into robo-speak, 2 will convert the string and then 3 will output it. "Exit" just says "Thanks for using the convertor" and stops the program. When the text is converted, if a word is more than 6 letters long it adds "zzz" to the beginning of the word, and if it's less than 6 letters it adds "eep-" to the beginning. I started off by assigning global variables: code:
code:
Zeether fucked around with this message at 23:31 on Feb 12, 2013 |
# ? Feb 12, 2013 23:15 |
|
Learn how to use the debugger. Open this up in the browser of your choice, open the console, and set a breakpoint on the start of your menu function. Then press buttons, and step through what's happening line-by-line. Especially the part that isn't working right. I've spoilered the answer so you can investigate it yourself and then check your result: Once you enter the first big if-block (i.e. when flag == 0), flag is ... 0! Which means that the following if-statements that check the value of flag are a little bit pointless. There are a few other issues in there too, but that's probably the first one you'll encounter. I won't comment too much on the structure of the code, I'll just note that you should really work on decomposing your application into little independent, testable bits instead of putting them all together in one big function.
|
# ? Feb 13, 2013 02:14 |
|
Hopefully one of you can help me but I am ready to pay someone to implement a rotator into my already existing script. I've made a thread on SAMart http://forums.somethingawful.com/showthread.php?threadid=3533585
|
# ? Feb 13, 2013 03:13 |
|
Jabor posted:Learn how to use the debugger. Open this up in the browser of your choice, open the console, and set a breakpoint on the start of your menu function. Then press buttons, and step through what's happening line-by-line. Especially the part that isn't working right. Fake edit: I got it to save and convert the text string. Now I just need to fix the "3" part and add the exit command.
|
# ? Feb 13, 2013 03:48 |
|
Right i'm playing around with javascript at the moment and would like some help with what should be a very simple problem but for some reason every time i try to solve it i can't. I'm trying to make a little script that populates an array and then does some maths using it. Basically what i would like it to do is something like this code:
|
# ? Feb 13, 2013 23:57 |
|
What you want to do seems reasonable. Where are you stuck?
|
# ? Feb 14, 2013 04:46 |
|
It won't accept forms[i] as an argumet and if I just set a name the thing breaks after the second input.
|
# ? Feb 14, 2013 15:07 |
|
I don't know what you code is suppose to do. But I have some comments to make (my comments inside the code) code:
this: newform(i){ //code here } is much better than this: newform(){ i = something.Foo.value; //code here } Modern browser have a console where you can type newform(33), and is easier to debug that way, because you control and debug, since you know what data is in 33. Consider learning OOP, have many adventages over pure functional c-like style of code. code:
Tei fucked around with this message at 15:48 on Feb 14, 2013 |
# ? Feb 14, 2013 15:45 |
|
Loving Africa Chaps posted:Right i'm playing around with javascript at the moment and would like some help with what should be a very simple problem but for some reason every time i try to solve it i can't. Here is a little script that populates an array and does some maths using it: JavaScript code:
Loving Africa Chaps posted:It won't accept forms[i] as an argumet and if I just set a name the thing breaks after the second input. What won't accept forms[i] as an argument? Nothing in your code uses forms[i] as an argument.
|
# ? Feb 14, 2013 16:05 |
|
Tei posted:
While you can append to innerHTML, often you should not, because first the contents of the parent-element get serialized and returned as the value of innerHTML, then they get deserialized into completely new set of elements. This is a problem when you do something like this: JavaScript code:
|
# ? Feb 14, 2013 16:18 |
|
Cool, thanks everyone. Starting to see the stuff I've been doing wrong. Very new to this but will go away and redo my rubbish code. Wheany posted:
Basically I want the page to do a meta analysis. The Maths stuff I've already got working with a pre-populated array it's just I'd like to be able to add studies from a webpage hence trying to add to an array via a form.
|
# ? Feb 14, 2013 16:52 |
|
Wheany posted:While you can append to innerHTML, often you should not, because first the contents of the parent-element get serialized and returned as the value of innerHTML, then they get deserialized into completely new set of elements. Using HTML as text (and not a nodes tree) has many problems, but make sense if you style of code is "C-like". With the C-like pure style, you would write code more like this: code:
I don't like it, (I am more a jquery guy) :P Tei fucked around with this message at 17:23 on Feb 14, 2013 |
# ? Feb 14, 2013 17:18 |
|
Loving Africa Chaps posted:Cool, thanks everyone. Starting to see the stuff I've been doing wrong. Very new to this but will go away and redo my rubbish code. So you have a web page that has a form with some fields? I assume that the html looks like the code in your earlier post: Loving Africa Chaps posted:
Do you want several such forms on the page at once, or do you have a single form that you reuse? Maybe you were after something like this: http://jsfiddle.net/m8hkz/
|
# ? Feb 14, 2013 17:53 |
|
Tei posted:Using HTML as text (and not a nodes tree) has many problems, but make sense if you style of code is "C-like". I much prefer code like this: JavaScript code:
JavaScript code:
Wheany fucked around with this message at 18:39 on Feb 14, 2013 |
# ? Feb 14, 2013 18:03 |
|
Wheany posted:... Makes sense. I have written a lot of code like your second example, and is tiring (in my defense: it was scripting in XUL, and there innerHTML is not recommended or flat out don't work). Is just easier to write this way: JavaScript code:
|
# ? Feb 14, 2013 18:23 |
|
Wheany posted:So you have a web page that has a form with some fields? One form that got reused, the fiddle is exactly what i was trying to do. Thanks so much!
|
# ? Feb 14, 2013 18:47 |
|
This is probably a Javascript related question but it's hard to put my finger on. I have these two iPhone web-app thingies (They're not actual web apps, I just open them in Safari). One of them prevents the iPhone from going to sleep when you leave it on the screen, the other allows the iPhone to sleep/autolock if you leave it running. If you visit http://dezigner.com.au/rhyscrape.php?updatespeed=2000 on iPhone safari, the phone will eventually sleep and autolock if you just leave it running. If you visit http://dezigner.com.au/rhyscrape_old.php the phone will just stay alive at full brightness no matter how long you sit there starting at it. We've tried it on two iPhones and we haven't disabled Autolock or anything like that. Can anyone give me a hint as to how on earth I caused the keep-alive in the original _old one, and why it's disappeared in the newer one?
|
# ? Feb 14, 2013 23:46 |
|
Mug posted:This is probably a Javascript related question but it's hard to put my finger on. code:
You can test this by going to your new page and touching the screen a few seconds after the page has loaded, then leave it alone. You'll see the page refresh once after about a minute and the phone won't auto-lock until about 2 minutes afterwards. Or you can change your iPhone's autolock to something else, like 2 minutes. That would fix it completely. In short: To fix it, change the refresh delay to something shorter, like 50 seconds.
|
# ? Feb 15, 2013 01:46 |
|
HTML code:
|
# ? Feb 15, 2013 02:44 |
|
Wheany posted:While you can append to innerHTML, often you should not, because first the contents of the parent-element get serialized and returned as the value of innerHTML, then they get deserialized into completely new set of elements. I learned this thanks to IE, where removing this line: JavaScript code:
|
# ? Feb 15, 2013 02:46 |
|
Cawd Rud posted:This was very interesting to look into, especially since auto-lock should not be something you can control from a web page. I did some experimenting and it's this line right here, which refreshes the page every 60 seconds: drat, I thought you'd figured it out. I changed the refresh to 50 seconds and it still goes to sleep 10 seconds after the auto-refresh I've updated it now to use the 50 second refresh so you can see if it's doing it on your end, too. edit: To give more info, the only reason that meta refresh is even in the new one is because I thought maybe that was what was disabling the auto-lock. (I don't need that refresh because Ajax does all the work anyway). Doesn't seem to work, though. So strange. Mug fucked around with this message at 03:08 on Feb 15, 2013 |
# ? Feb 15, 2013 03:04 |
|
Mug posted:drat, I thought you'd figured it out. I changed the refresh to 50 seconds and it still goes to sleep 10 seconds after the auto-refresh Actually, sometimes your new page works, and sometimes it doesn't. It's inconsistent. In fact right now I couldn't get it to auto-lock at all with the new page running until I locked and unlocked myself, then tried it again. Try this for me: load up the page. See it refresh at the 50sec mark. When the screen dims (but before it locks), tap on it to light up the screen again. Confirm that it doesn't auto-lock after that. For my initial post I was testing with just a blank page with only the refresh meta tag and nothing else. I tried that with a 50 second delay and it worked. Now I'm only more curious why your new page doesn't behave this way. This is some very strange behavior. I'll attempt to do test some more theories, but right now
|
# ? Feb 15, 2013 05:38 |
|
Do you think the Ajax calls cause more battery drain that the iPhone wants to lock, but the lack of Ajax means the phone will stay awake in the old version? I mean, there's no way the iPhone specification ever indicates this behavior, but I was curious as to whether maybe that's what was happening. I'll play with it a little more soon. I've just got a few other things to work on right now, too.
|
# ? Feb 15, 2013 05:50 |
|
Suspicious Dish posted:
Okay, now I have a new preference.
|
# ? Feb 15, 2013 07:45 |
|
Suspicious Dish posted:
cloneNode is awesome for other reason than clarity: is loving fast. I had some table, with columns, headers,and data in it. And rebuilding it with Javascript was really slow. So what I did was cloneNode the tree of the table empty, and replace it every time I had to start again with the table, this made a slow operation instantaneous. Having html already in the page, hidden or inside a magic tag like <script language=template>, allows your serverside templating engine to control it. If your designer is the one writting the templates, you allow your designer to control the final html. This is ****much**** better than having HTML hardcoded in javascript. It gives the control of the html to the right person.
|
# ? Feb 15, 2013 14:26 |
|
It also gives you syntax highlighting, which is what I like.
|
# ? Feb 15, 2013 21:47 |
|
Any advice on how to best manage complexity for larger fat client JS apps? I'm mostly modularizing as much as I can at this point, anything else that works really well for you?
|
# ? Feb 16, 2013 23:56 |
|
|
# ? May 16, 2024 23:23 |
|
DreadCthulhu posted:Any advice on how to best manage complexity for larger fat client JS apps? I'm mostly modularizing as much as I can at this point, anything else that works really well for you? I've found that modularizing has diminishing returns as the size and complexity of the app grows. You reach a point where you have to split your code up into separate files and directories in order to separate concerns and keep things sane. To avoid having 15 separate HTTP calls in your app, there are build tools like Require.js that can concatenate all the files across your entire project into a single, minified file for production.
|
# ? Feb 17, 2013 05:29 |