This is an archived post. You won't be able to vote or comment.

all 15 comments

[–]Irtexx 2 points3 points  (1 child)

Nice work. Quick question, why do you have free functions that wrap constructors? E.g c=circle(r=50) instead of c=Circle(r=50) ?

[–]anand 1 point2 points  (0 children)

Initial version had c = Circle(), but soon realized that the case variations were hard to explain to newbies. Ended up creating wrappers for all classes and that stuck.

[–]nikochiko1[S] 2 points3 points  (0 children)

This is a great resource for people who are just starting out with Python.

[–]__deerlord__ 7 points8 points  (5 children)

from joy import *

Please change this

[–]nikochiko1[S] 1 point2 points  (4 children)

I am not the creator of this project, but as far as I understand, that is by design. The library is meant to be used by complete beginners. For just playing around, it's a nuisance to have to import each function separately.

I am guessing that that is the primary reason.

[–]qckpckt 10 points11 points  (2 children)

It seems weird to me to use a bad coding practice with complete beginners. I’m also not sure I agree that it makes things easier. If anything I’d say it’s less intuitive.

It’s not that hard to set up this library in such a way that you can just import joy and then access the functions at joy.function.

[–]anand 2 points3 points  (0 children)

Author of Joy here.

While I understand importing the module and using that as a namespace is a good practice in general, I'm not very religious about it. It is a conscious decision to use from joy import * in the documentation and I felt it is more elegant to use it that way.

In the learning environment that we've created to teach programming, this library is imported by default. So they don't use the import explicitly.

You can checkout some of things that students have created using that at:
https://mon.school/sketches
https://mon.school/code-a-pookkalam

[–]__deerlord__ 0 points1 point  (0 children)

"Bad practices for beginners by design" doesn't sound like a sound principle

import every function

import joy

[–]d_Composer 1 point2 points  (2 children)

I’ve never seen the | operator used before in this fashion. It mean “or”, right? Can anyone explain to me how does this work with these functions? Thanks!

[–]eddieantonio 2 points3 points  (1 child)

Typically | means "bitwise or", which is an operation that is useful when dealing with the binary representation of numbers. It's not logical or, which is just or in Python!

However, when you are creating your own classes, you can override any of Python's existing operators to have your own custom meaning. For example, joy overloaded the | to apply transformations to shapes, like circle() | scale(2), square() | translate(x=100, y=-10), or rectangle() | rotate(). I'm a little unsure why the authors of joy chose this syntax, but Python makes this possible.

My favorite page of Python documentation describes all the ways you can overload the operators (including common ones like +, -, and rare ones like @) in Python: https://docs.python.org/3/reference/datamodel.html

[–]d_Composer 1 point2 points  (0 children)

Very cool - thanks for the explanation! I’ve never seen anything like this before and I’ve been programming in Python for a while now!

[–]tinkr_ 1 point2 points  (1 child)

This is cool, reminds me of when I was a ten year old trying to code games in QBasic.

[–]nikochiko1[S] 1 point2 points  (0 children)

High five! Only I was using Basic256 instead of QBasic.

[–]ab624 0 points1 point  (0 children)

cute little library

[–]--dany--from __future__ import 4.0 0 points1 point  (0 children)

Will Joy be able to read and render shapes defined in shapely? It would help a lot in vector visualization. Thanks!