I've always wanted to have an MC clone in Python with GUI event hooks to run scripts. Like pull a lever and an email is sent sort of thing. Will this fork allow for something like that? I'm not against adding it myself if allowed, btw.
Pycraft: Minecraft engine in Python
11–20 of 49 posts
Re: Pycraft: Minecraft engine in Python
#12It seems like a harmless enough thing to do but that code is effectively creating a new array with values [1, 2, 3, 4, 5] and testing if the result of len() is in that array by iterating over it. This check is happening multiple times for each draw call every frame.
Sadly I see this kind of stuff in Python all the time and it just adds weight to the argument that Python is not a performant language. 1 <= len(vals) <= 5 would have been more pythonic and certainly more efficient (and obvious) but I have to wonder if under the hood it's just doing the same inefficient operation.
Re: Pycraft: Minecraft engine in Python
#13Earlier quoted context omitted.
Yes, you are correct. But normal MC is not open source. :)
Even though Notch was supposed to make it open source at some point. Another broken promise.
That said, they also promised a modding API too...
Re: Pycraft: Minecraft engine in Python
#14I cringe when I see code like this: if len(vals) in range(1, 5): It seems like a harmless enough thing to do but that code is effectively creating a new array with values [1, 2, 3, 4, 5] and testing if the result of len() is in that array by iterating over it. This check is happening multiple times for each draw call every frame. Sadly I see this kind of stuff in Python all the time and it just adds weight to the arg…
dis.dis(lambda: 1 > 27 ROT_TWO
28 POP_TOP
29 RETURN_VALUE
Compare to: dis.dis(lambda: len(vals) in range(1, 5))
1 0 LOAD_GLOBAL 0 (len)
3 LOAD_GLOBAL 1 (vals)
6 CALL_FUNCTION 1
9 LOAD_GLOBAL 2 (range)
12 LOAD_CONST 1 (1)
15 LOAD_CONST 2 (5)
18 CALL_FUNCTION 2
21 COMPARE_OP 6 (in)
24 RETURN_VALUERe: Pycraft: Minecraft engine in Python
#15I cringe when I see code like this: if len(vals) in range(1, 5): It seems like a harmless enough thing to do but that code is effectively creating a new array with values [1, 2, 3, 4, 5] and testing if the result of len() is in that array by iterating over it. This check is happening multiple times for each draw call every frame. Sadly I see this kind of stuff in Python all the time and it just adds weight to the arg…
Agreed that 1 <= len(vals) < 5 would be more Pythonic.
Re: Pycraft: Minecraft engine in Python
#16I cringe when I see code like this: if len(vals) in range(1, 5): It seems like a harmless enough thing to do but that code is effectively creating a new array with values [1, 2, 3, 4, 5] and testing if the result of len() is in that array by iterating over it. This check is happening multiple times for each draw call every frame. Sadly I see this kind of stuff in Python all the time and it just adds weight to the arg…
Why do you suspect 1 You can actually get a very good idea for what Python is doing under the hood using the dis module: dis.dis(lambda: 1 > 27 ROT_TWO 28 POP_TOP 29 RETURN_VALUE Compare to: dis.dis(lambda: len(vals) in range(1, 5)) 1 0 LOAD_GLOBAL 0 (len) 3 LOAD_GLOBAL 1 (vals) 6 CALL_FUNCTION 1 9 LOAD_GLOBAL 2 (range) 12 LOAD_CONST 1 (1) 15 LOAD_CONST 2 (5) 18 CALL_FUNCTION 2 21 COMPARE_OP 6 (in) 24 RETURN_VALUE
This output doesn't really provide any clarification.
Re: Pycraft: Minecraft engine in Python
#17Re: Pycraft: Minecraft engine in Python
#18I cringe when I see code like this: if len(vals) in range(1, 5): It seems like a harmless enough thing to do but that code is effectively creating a new array with values [1, 2, 3, 4, 5] and testing if the result of len() is in that array by iterating over it. This check is happening multiple times for each draw call every frame. Sadly I see this kind of stuff in Python all the time and it just adds weight to the arg…
This is in Python 3. xrange is now range, so only a generator is constructed. Agreed that 1 <= len(vals) < 5 would be more Pythonic.
"x in range(10)" will operate in constant time and memory in Python 3. Whether it is actually more efficient than "0
$ python3 -m timeit -s 'x = 8' 'x in range(10)'
1000000 loops, best of 3: 0.351 usec per loop
$ python3 -m timeit -s 'x = 8' '0
Even aside from this, I find the "0 <= x < 10" syntax to be clearer.Re: Pycraft: Minecraft engine in Python
#19Re: Pycraft: Minecraft engine in Python
#20I cringe when I see code like this: if len(vals) in range(1, 5): It seems like a harmless enough thing to do but that code is effectively creating a new array with values [1, 2, 3, 4, 5] and testing if the result of len() is in that array by iterating over it. This check is happening multiple times for each draw call every frame. Sadly I see this kind of stuff in Python all the time and it just adds weight to the arg…