Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: I don't get it Date: Tue, 13 Apr 2021 14:58:12 +0100 Organization: A noiseless patient Spider Lines: 75 Message-ID: <87y2dmmgln.fsf@bsb.me.uk> References: <1e965vkgenq7l$.hqmrkifgr4m5$.dlg@40tude.net> <586d1b88-77d5-42b0-ae5b-7506307df499n@googlegroups.com> <957a79db-946e-4f23-931a-ef7d4f0dbb3cn@googlegroups.com> <305fecc4-43da-4378-8430-ed10ac4dbe5bn@googlegroups.com> <20917gl3dv8shs6qqf1dqginq69e50aa54@4ax.com> <8735vytcwa.fsf@bsb.me.uk> <87lf9qrozz.fsf@bsb.me.uk> <875z0tq723.fsf@bsb.me.uk> <8b594439-379f-431f-8bf6-43c8066d3525n@googlegroups.com> <87o8ejpzv0.fsf@bsb.me.uk> <845c8b8e-d415-4b41-8327-6b31bc50825an@googlegroups.com> <1ae0aa1d-162d-4666-acf9-50376e1acd9fn@googlegroups.com> <8090782c-7564-4881-a97e-70dd1e865674n@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: reader02.eternal-september.org; posting-host="f2852c40764e8d2c18a878782c677cb9"; logging-data="9342"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ureBy2qmiPcvSWGrxddrlHUT4u5dXfMc=" Cancel-Lock: sha1:UNvHjQpg55DnuTSnDpWLAZ8otNc= sha1:I+l90/PJjGj5bWzhYRTjeTAKnWc= X-BSB-Auth: 1.ac66fad83f5c267459dc.20210413145812BST.87y2dmmgln.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:39918 Jonas Thörnvall writes: > måndag 12 april 2021 kl. 23:32:18 UTC+2 skrev sc...@sauyet.com: >> Jonas Thörnvall wrote: >> > Ben Bacarisse wrote: >> >> >> Your code is unmanagable. Almost any part of it can alter the behaviour >> >> of any other part. You might be sure what parts do what (though your >> >> repeated requests for help suggest you probably no longer know what the >> >> code is doing) but other people will find it almost impossible. >> >> >> >> Your best bet is to re-write it step by step making sure that functions >> >> are genuinely self-contained actions. Not only will the result be >> >> easier to modify, you will probably find the problem on your own. >> > You are dreaming Ben it is a single function with ten lines of code >> > and just two global arrays. >> The first three lines of this single "function" are >> | function STARTPLAY(){ >> | if (keepGoing) { >> | stopRec=setTimeout(STARTPLAY,copyEv[playPos]); >> We have four free variables used here: `keepGoing`, `stopRec`, `copyEv`, >> and `playPos`. There are at least ten more in the remainder of the >> snippet you passed. >> >> This is horrible. >> >> Ben was, if anything, too kind. >> > Well those can't possibly effect anything going on in recursion of > function, not even the understaning of it. Even you can't understand it. You are arguing with people who have, I suspect, many decades more experience than you do in debugging horrid code. The advice to write it properly is not given flippantly. It is by far the best course of action. > function STARTPLAY(){ > if (keepGoing) { > setTimeout(STARTPLAY,copyEv[playPos]); > REALTIME=performance.now()-browserLoadTIME; > LATENCY=REALTIME-oldPassedTime; > oldPassedTime=schedTime; > schedTime=copyEv[playPos]+schedTime; > copyEv[playPos]=Math.max(0,copyEv[playPos]-LATENCY); > outportarr[outportindex].send(noteMessage[playPos]); > playPos++; > } > } > https://jonasth.github.io/ > What is so hard to understand about function nothing, the hard thing > is to understand why it does not work. If it's easy to understand, why don't you know what it's doing? You need to ditch this distinction between understanding it and understanding why it does not work because they are the same thing. This is about the first step every programming student has to take. You must stop thinking you know what you wrote. The function is doing exactly what you wrote. If that's not what you want or need, then you need to understand it better. Other people may be able to help, but I, for one, am not going to try unless you put some effort into writing it properly. You are, I think, doing this for fun, yes? If it remains fun to be puzzling out what's going on, then you really don't need any help. Just keep going as you are. But if the fun comes from getting things to work, then learning how to program will be a huge benefit. There is, usually, much more fun to be had from productive coding than poking about in a mess you don't quite follow. -- Ben.