Not a python question, just programming logic trap?

jonas.thornvall at gmail.com jonas.thornvall at gmail.com
Thu Mar 14 00:49:11 EDT 2019


Den onsdag 13 mars 2019 kl. 21:56:56 UTC+1 skrev Rick Johnson:
> On Wednesday, March 13, 2019 at 3:23:50 AM UTC-5, jonas.t... at gmail.com wrote:
> > Anyone who is good at see logic traps in programming? comp.lang.javascript is defunct so i try here.
> > 
> > Using the metronome. 
> > 
> > https://midisequenser.000webhostapp.com 
> > 
> > I've tried to understand how following code can lead to that after the keyreleased the front of the keyed scrollbar raise/extend faster while the backend stay correct "in sync". One could think/imagine xFrontStart=scrollBarPos-FRONTOFFSET; somehow executed  more then once after release, but how could it, the keyrelease is true only in that part of code and only done once??? 
> 
> First of all: this a Python group, so; if you want to ask a question, then write your code in Python syntax and then present it here. And if you don't know Python syntax, well; think of this as a good excuse to learn. :-)
> 
> Secondly: If your issue is related to _logic_, then the bodies of those conditions is nothing but loud, distracting noise. My advice is to (1) simplify the statements in each clause, and (2) replace the entire body of each condition with a call to stdout. 
> 
> For instance, this code:
> 
>   if(mess.data[0]==NOTE_ON && keyreleased==false){ 
> 
> Could be replaced by this Python code:
> 
>   #
>   # First, unpack some values.
>   #
>   firstMessage = mess.data[0]
>   firstMessIsNoteOn = (firstMessage == NOTE_ON)
>   #
>   # Now, begin the logic.
>   #
>   if firstMessIsNoteOn and (not keyreleased):
>       print('clause-1')
>   elif ...
>       print('clause-2')
>   #
>   # You fill in the rest!
>   #
>   else:
>      print('else-clause')
> 
> 
> Here endeth the lesson. (for now!)
> 
> PS: Boy, this code sure was a "mess" :-)
> 
> PPS: My example code was not checked for syntax errors.

Nah i can't see the error is due to the "If clause" branching possibly it should been an elseif at instead of separate if. No there is something going wrong with the variables.



More information about the Python-list mailing list