Jump to content

Wikipedia:Reference desk/Archives/Computing/2015 February 23

From Wikipedia, the free encyclopedia
Computing desk
< February 22 << Jan | February | Mar >> February 24 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


February 23

[edit]

Programming - is/uses/is easier if you know - math

[edit]

What of the three possibilities is closer to reality? --Senteni (talk) 00:04, 23 February 2015 (UTC)[reply]

Programming is easier if you know math, in the sense that if you've had a lot of trouble with things like equations and algorithms and proofs in math, you'll have a lot of trouble programming. Some programming uses math, but by no means all, and some programming uses no math whatsoever. Programming is not, however, math. --jpgordon::==( o ) 00:26, 23 February 2015 (UTC)[reply]
I did various types of programming for about 25 years. The only need for "math" I ever had was an understanding of bases (decimal=base 10, binary=base 2, hexadecimal=base 16), and that was only after I had moved into the more technical side of software dev. Most programming needs no particular math skills at all, although it often helps to have a calculator handy. ―Mandruss  03:17, 23 February 2015 (UTC)[reply]
Think it's worth quoting the first paragraph of our Mathematics article:
"Mathematics ... is the study of topics such as quantity (numbers), structure, space, and change. There is a range of views among mathematicians and philosophers as to the exact scope and definition of mathematics."
So, holding that definition (and the fact that mathematicians don't agree on it!) in our heads, let's try to answer your question:
  • Programming is math - in the purest sense of that definition of mathematics, yes. Numbers, structure, space (in terms of data space, configuration space, etc) and change are a lot to do with what programming is. We programmers deal with flow-control, algorithms and data structures - all of which are broadly mathematical in nature. So, I suppose programming is a branch of mathematics - but one that's quite disjoint from the rest of mathematics, and one that not many mathematicians would identify with.
  • Programming uses math - well, if programming is math, then it obviously uses it - but you'd be hard pressed to find anything beyond the very basics of arithmetic, boolean logic and set theory that applies to all branches of programming. But obviously if (like me) you're a graphics programmer, then you'll be using a ton of geometry, topology, trigonometry and matrices. But if you're into image processing, then you'll be interested in statistics and all sorts of other mathematical concepts. There are many results from mathematics that are used in programming...but not all programming uses much more than the very most basic arithmetic and boolean logic. There are programming languages like Prolog that would be perfectly useful without numbers of any kind.
  • Programming is easier if you know math - not exactly. I think it's true that the kinds of people who excel at algorithms and data structures tend to be the kinds of people who do well in mathematics. On the other hand, I've known plenty of decent mathematicians who took up programming and did a horrible job of it. So there are no guarantees! I've spent a lifetime as a well paid programmer without ever needing my patchy recollection of high school calculus...but in the field of graphics, I've needed to trawl through many other areas of mathematics.
SteveBaker (talk) 04:15, 23 February 2015 (UTC)[reply]

Display problem in Wikipedia editing window

[edit]

I frequently use an HP laptop computer (running Windows Vista) to edit Wikipedia pages. For some reason, the type in editing windows on Wikipedia began appearing in really poor quality. It looks much like the output of a typewriter whose ribbon has been used so much that most of the ink has been used up.

I have tried Chrome, Firefox and Opera. The same low-quality display appears in all three. The only way I can get a decent editing window display is to use Internet Explorer 9 (the latest version supported by Vista).

The problem occurs only in Wikipedia's editing windows. Articles are displayed as clearly as ever, and I have had no problems with pages from other Web sites.

If you have any suggestions, I would appreciate them. Eddie Blick (talk) 03:42, 23 February 2015 (UTC)[reply]

Sometimes non-integer magnifications of small text can look like crap. Try changing the zoom level, usually with CTRL + and CTRL -. StuRat (talk) 04:36, 23 February 2015 (UTC)[reply]
Another thought is that some older computers could only display 256 colors at top resolution. If the (multi-shaded) text puts it over that limit, many of the shades might just come out white. So, try increasing the color depth (which likely requires lowering the screen resolution). StuRat (talk) 04:43, 23 February 2015 (UTC)[reply]
I think any laptop that can run Vista is way too recent to have that problem. Anyway, web browsers on 256-color displays used a fixed palette, not dynamic color allocation, so they couldn't run out of colors. -- BenRG (talk) 05:36, 23 February 2015 (UTC)[reply]
Thanks. The last time I observed this problem was on my Windows 98 laptop, but I wasn't sure when they finally cured it. StuRat (talk) 06:43, 23 February 2015 (UTC)[reply]
This was probably caused by the Windows update http://support.microsoft.com/kb/3013455. That page has a link to http://support.microsoft.com/kb/3037639 which fixes it. I had the same Windows Vista problem (which also affected articles and other websites to a lesser extent in my case), and the fix worked. Download and install the update from http://support.microsoft.com/kb/3037639. It isn't offered in a normal search for Windows updates. Before Microsoft made the fix, I chose "Sans-serif font" at Special:Preferences#mw-prefsection-editing, "Edit area font style". Many others unistalled kb3013455. PrimeHunter (talk) 04:48, 23 February 2015 (UTC)[reply]
Thanks for providing that link. I wondered if a Windows update might have caused the problem, but I didn't know a solution if that should be the case. I'll try the link that you suggested. Eddie Blick (talk) 15:17, 23 February 2015 (UTC)[reply]
That took care of the problem. I downloaded the patch from the link you provided, then installed the update. After a restart, the editing windows are back to normal legibility. I appreciate your help! Eddie Blick (talk) 17:21, 23 February 2015 (UTC)[reply]

Help with PHP confused with calculation

[edit]

Hello, I am a novice at PHP and I needed to find a way to complete this form I wanted to make. The form has multiple questions it asks like the characters name and the race of your character and what kind of stuff you would like to buy. There are 4 form questions that end in a drop down box method and 1 of them asks you your race and the other 3 ask you how much of each item you would like to buy. I wanted to process in php a way to add gold to the specific races. If you picked human you would get no extra gold and if you chose elf you would get 10 extra gold added to your character so then when you submit the form if you had an elf that start with 10 gold and added 10 gold to the amount the starting gold was which was 10 you would get 20 gold for an elf character. Then you could of selected 10 gold worth of one item and 5 worth of another item and 0 worth of another item and then after check out you would have 5 gold left on your character. How can I do this? I also wanted to make it so that if you go over the amount of gold that your character has you will get an error screen telling you that you dont have enough gold. — Preceding unsigned comment added by 204.42.31.250 (talk) 12:28, 23 February 2015 (UTC)[reply]

It would be hard to answer this question without actually writing all of the code for you - which would prevent you from learning anything from the exercise. But the fact that you need to ask it suggests that you need to work a little longer with PHP tutorials and examples before launching into this kind of project. When you do start into it, you'll need to ask yourself some questions:
  • How do you collect the information from the HTML form when they hit "SUBMIT"? (HINT: Read up on $_GET and $_POST)
  • How do you know how much gold the person had before they entered into the web page? Perhaps you need to record that in a database somehow? Can you ask them how much they have?
  • How will you store the list of character races and the amount of bonus gold they get? Are there few enough (and a fixed number that's unlikely ever to change) that you can just code that information directly into the PHP program - or will someone who is not a PHP programmer need to expand or change that list in the future?
  • How will you store the list of available items in the store and their prices? Are you sure that there will never be more than three kinds of item on sale? And again, can you be sure that the list would only ever be changed by a PHP programmer in the future?
  • Will you be able to prevent someone cheating by buying a negative number of one of the items in order to buy a lot more of the others? (HINT: Check, if the number of items purchased is less than zero, then either just set it equal to zero - or send them to an error page.)
I strongly suggest that you get the HTML form working first and verify that it passes the right data to your PHP program. If you use the "GET" method for sending the data (definitely the easiest to debug at this stage!) You'll want the HTML to try to call up a URL something like this:
http://myPage.com/myPHPscript.php?race=human&numSwords=0&numArrows=5&numFoodRations=2
Then, write your PHP code to just "echo" back the race and item quantities so you can be sure that you're getting the right data in the right places.
Once you know that the right data is getting into your PHP code, then you can start saying things like "if ( $_GET['race']=='elf' ) $gold += 10 ;" ...and... "$gold -= $costOfSword * $_GET['numSwords"] ;" ...and..."if ( $gold < 0 ) echo 'You don't have enough gold to buy all that stuff!' ; else echo 'Thank you for shopping at the Adventurer Emporium, you have '.$gold.'gp left.' ; "
Good luck! And by all means come back and ask us more detailed questions as you get closer to having something working. SteveBaker (talk) 15:57, 23 February 2015 (UTC)[reply]
To me it logically makes more sense to have two forms, the first where you ask details about the character, and the second where they choose what initial items to buy, based on their selections on the first form. StuRat (talk) 16:44, 23 February 2015 (UTC)[reply]
I agree, but generally we're here to solve the problem we're given, and there may be other constraints here. The main reason to do it as you say is that it allows the user to know how much gold (s)he has BEFORE trying to spend it...but on the other hand, they might want to change their selected race in order to enable them to get the equipment they want...which would be harder with two pages. Personally, I believe in doing the calculations in JavaScript interactively, so that the user can see their gold totals going up and down as they change the options on the page - and just having the PHP code verify the results to avoid cheating. But we clearly have a beginner at this kind of work, and complicating things at this point would be counter-productive. SteveBaker (talk) 06:04, 25 February 2015 (UTC)[reply]
Perhaps a back button to return to the first form would be a way to enable the "two forms option" to allow changing the character race and get more gold. StuRat (talk) 06:45, 25 February 2015 (UTC)[reply]

Thank you very much SteveBaker, this response does help a lot and I am getting better at understanding the exercise. I definitely don't want you to write the code for me then I wont learn anything so thank you for that! So far I have managed to make a if statement that adds the money to the race it is meant to but I have yet to get down the calculation part. I am a bit lost on that. The HTML form is perfectly fine I have a few years experience with that. I now need to make the php page tell you if you have spent to much money and that you have an error because of it and I need to calculate how much money was spent and how much is left. — Preceding unsigned comment added by 204.42.31.250 (talk) 16:48, 23 February 2015 (UTC)[reply]