Wikipedia:Reference desk/Archives/Computing/2017 March 17

= March 17 =

A programming newbie question Regarding function arguments
My question can actually be comprised of the following 3 questions which kind of completes one eachother. Given I personally study Javascript, and some people I know do so as well, I would suggest orienting the answer in Javascript if it is possible.


 * 1) Why do we pass certain values to functions instead of just using a well defined code inside the function without such argument? Another tongue to this question could be "Could we achieve a result achieved with an argument, without using an argument in parenthesis?".
 * 2) Is tottaly avoiding function arguments should drastically sabotaging or limiting what one can do with the language, or it doesn't really matter and everything could be achieved with other, rather longer and more defined codes inside the function?
 * 3) Is there any programming paradigm in which programmers avoid ahead of passing arguments to functions and if so, what are the 1-2 main industries that use such a paradigm, that you might think of?

Much thanks to you! 79.178.144.67 (talk) 14:31, 17 March 2017 (UTC)


 * Not an answer, but a note... I have been programming since 1972 and this is the very first time I've heard the phrase "arguing arguments." I assume you are using "argue" in the way that "pass" has been used since the invention of functional programming, but I cannot be certain. Is "argue" a new buzzword in JavaScript programming? 209.149.113.5 (talk) 16:21, 17 March 2017 (UTC)
 * I've taken programming courses as recently as 3 years ago and I've never heard it. In fact, I can't really parse what the OP is actually asking, else I'd have answered. I think they're asking about modularity, and why we put code in a function rather than simply using the code in place of calling the function that contains that code. Mostly that's to save programmers a lot of typing. When the code is compiled, that's how it works. Machine code is always imperative in that it is a long series of instructions the processor follows, one at a time. ᛗᛁᛟᛚᚾᛁᚱPants   Tell me all about it.  16:34, 17 March 2017 (UTC)
 * I had a gut feeling that the question was asking why we allow for calculations in function calls as in foo(a+3); and asking why shouldn't we use foo(a) and put a+3 in the function. But, that way of reading it only goes so far and starts to fall apart quickly. Hopefully the person comes back and asks a clearer question or explains that there is a new uber-cool feature of "arguing" arguments in JavaScript and I'm just getting too old to keep up with the changes. 209.149.113.5 (talk) 16:53, 17 March 2017 (UTC)
 * Hi, I was unorthodox when saying "arguing" instead of "passing". I've now rephrased my question. I hope it is now clearer enough. Thank you for your time! 79.178.144.67 (talk) 17:22, 17 March 2017 (UTC)
 * ...there is a new uber-cool feature of "arguing" arguments...   ᛗᛁᛟᛚᚾᛁᚱPants   Tell me all about it.  18:02, 17 March 2017 (UTC)


 * Let me attempt to answer. Passing arguments to and from functions and subroutines is just one way to get data in and out.  Some alternatives:


 * 1) For browser apps, you could store data to cookies and read it back out.


 * 2) You could write to and read from a file.


 * 3) You could use a designated region of memory and write to and read directly from that memory location.


 * 4) In FORTRAN they have a COMMON BLOCK, designed explicitly for this purpose. Other languages may offer something similar.


 * These are generally a bad idea, though. Consider if you are trying to debug a program you didn't write (or don't remember), and you know that at one point a particular variable has a bad value in it.  You also know it had a good value in it, many steps back.  In between, many functions and subroutines are called.  With an argument list, you should be able to see exactly which functions and subroutines might mess with that variable, and look inside each of those to try to find the bug.  But, without that argument list, you have no idea which functions and subroutines mess with which variables, making debugging much harder.  This gets worse if each of those functions and subroutines also calls others, without argument lists, which then call others, etc. StuRat (talk) 20:12, 17 March 2017 (UTC)


 * Maybe you know this but I'm not certain from your post so let me just say it: The main reason for having arguments in functions is to be able to call the same function multiple times with different arguments which affect what it does. For example, a function to draw a circle would be of limited use if you had no way to specify the location or size. Function arguments is a very popular way to give such data to functions. Programmers love that they can specify and see in the function call what data is passed to the function. Most languages have alternatives like first storing the data somewhere the function has access to and then call the function without arguments. Source code doing this is often more difficult for programmers to write, adapt and debug. PrimeHunter (talk) 20:48, 17 March 2017 (UTC)


 * Forth is a language that don't have parameter passing as such (and the language doesn't control params for number and type). yet it's not limiting at all because all subroutines ("words" in Forth-speak) operate on an implicit stack. I'll leave finding out what "paradigm" Forth is and which "industries" use it as an exercise for the OP since the Q sounds awfully like homework. In essence, this means all subroutines are variadic by default and the subroutine constructs its own argument list at runtime (Perl has something similar, I think.) Basic (any dialect) OTOH doesn't have a stack, thus subroutines you call with GOSUB operate on global variables, which is very limiting, but even more limiting is the fact they have to return the return values via global variables, too. The quality of taking a certain number of params is called arity and yes, you can do anything having only nullary functions Asmrulz (talk) 10:57, 18 March 2017 (UTC)


 * Versions of Structured BASIC do have a stack, and local variables in procedures, but I agree that those called by GOSUB in basic BASIC have neither.   D b f i r s   12:04, 18 March 2017 (UTC)

Why did my computer stay on all night?
I did: turn the Windows 10/Microsoft Edge computer off using the sleep button. It did: came back on during the night, with the orange light on the back flashing. I believe that if I am not actively using the Internet, this orange light indicates that software is being downloaded. I expected: the computer to turn itself off after the download finished, but it seemed to stay on all night long, and with my new faster Internet speed, I can't imagine how that much software would be downloading.

Previously, updates were being downloaded automatically, but if I found a progress report for a particular update, it should have had a percentage that kept going up as the software downloaded. Instead it got stuck and I was never able to figure out why, but I suspected my slower Internet speed, which would have been very expensive to increase.

Now, I have to wonder if there is still a bug that is preventing the download from being completed, but I don't know how to determine what is happening. There must be someplace where I can see what was taking place during these long nights of downloading.— Vchimpanzee  •  talk  •  contributions  •  20:28, 17 March 2017 (UTC)


 * Don't know why the download stalled, but that explains why the PC stayed on. Unless the O/S added a check to give up after a certain amount of time and power down, it will wait forever for the download to complete.  It might well shut down if the download actually fails, though, rather than just stalling.  StuRat (talk) 20:54, 17 March 2017 (UTC)


 * Actually, I haven't seen that the download actually stalled when the computer stayed on all night. I was describing what used to happen. What I'm trying to find is a way to see what is happening when the computer stays on all night, if such a thing is possible.— Vchimpanzee  •  talk  •  contributions  •  15:52, 18 March 2017 (UTC)


 * It may worth finding out exactly what wakes it up. You may only need to instruct it to go back to sleep again after its finished whatever its doing. Prevent your PC from waking up automatically. Do please,give some feed-back on anything you discover as it may be useful to other readers.--Aspro (talk) 23:30, 18 March 2017 (UTC)


 * BTW, the ultimate way to stop your PC from waking up at night, if all else fails, is to unplug it. For a laptop, you would also need to remove the battery. StuRat (talk) 01:46, 19 March 2017 (UTC)


 * FWIW, around the same time as the OP's question I was instructed to restart my (Windows 10) PC to complete installation of an update: when I did so it permanently stalled on the message "Installation in progress, do not turn off your computer" or words to that effect.
 * I had to power off the PC eventually as I was physically rearranging my setup and needed to unplug various cables. When I eventually powered up again no problems were evident. It may be that the OP experienced a similar glitch. {The poster formerly known as 87.81.230.195} 2.123.26.158 (talk) 03:04, 19 March 2017 (UTC)
 * I know I could unplug it but I'd rather not. I'm still trying to find the answer about what was downloading. On another site, they kept telling me to do stuff and when my computer couldn't do it, no replies. No attempt to do anything.— Vchimpanzee  •  talk  •  contributions  •  14:19, 21 March 2017 (UTC)