Re: A curiosity question

2019-05-20 Thread AudioGames . net Forum — Developers room : Sam_Tupy via Audiogames-reflector


  


Re: A curiosity question

Technically it sets it, but I'd imagine that checking each time whether it's true vs resetting it to true even if it is already true would execute at roughly the same speed, so you can do either, at least for things like booleans and other simple variables. But once you get into more advanced objects that must be initialized, you'll want the first approach as it will run considerably faster. For example:bio=Nonefor i in range(10):    if i>5 and not bio: bio=io.BytesIO(someLongString)would execute much faster than if you had removed that second claws of the statement, because making a new BytesIO object with your string is internally harder work than assigning to a bool. I also tested this, it seems the first approach when comparing rather than always setting, even with bool, run 10 times is just a couple ms faster than the second approach, where you set it no matter what. The difference is so small in that case it probably doesn't matter though, however I'd still avoid it in longer loops, or programs where your goal is efficiency rather than simple code that just works. But you should really avoid it when actually making new objects, as that is much more intensive. and should only be done if your object doesn't already exist.

URL: https://forum.audiogames.net/post/435090/#p435090




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: A curiosity question

2019-05-18 Thread AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector


  


Re: A curiosity question

Both of those examples would do the same thing. In the first case if I isn't greater than or equal to 5, the if statement won't trigger because both statements need to be true because you put "and" between them. So if something is False it will trigger when I is greater than or equal to 5, and if something is True, it won't matter because the purpose of the if statement is to make something true anyway, which makes checking if something is true or false pointless. Now, if you put an OR statement between the checks, then whenever something is False it would set it to True, making the I is greater than or equal to 5 statement irrelevant. The second statement skips all this by just checking if I is greater than or equal to 5, which sets something to True whether it is already or not, which ultimately doesn't matter.

URL: https://forum.audiogames.net/post/434673/#p434673




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: A curiosity question

2019-05-18 Thread AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector


  


Re: A curiosity question

Both of those examples would do the same thing. In the first case if I isn't greater than or equal to 5, the if statement won't trigger because both statements need to be true because you put "and" between them. So if something is False it will trigger when I is greater than or equal to 5, and if something is True, it won't matter because the purpose of the if statement is to make something true anyway, which makes checking if something is true or false pointless. Now, if you put an OR statement between the checks, then whenever something is False it would set it to True, making the I is greater than or equal to 5 statement irrelevant. The second statement skips all this by just checking if I is greater than or equal to 5, which sets something to True.

URL: https://forum.audiogames.net/post/434673/#p434673




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: A curiosity question

2019-05-18 Thread AudioGames . net Forum — Developers room : ironcross32 via Audiogames-reflector


  


Re: A curiosity question

it would set each time through.

URL: https://forum.audiogames.net/post/434667/#p434667




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector