Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.

Which do you prefer to use?
Java
 29%  [ 5 ]
Python
 47%  [ 8 ]
I don't know / Neither / Both
 23%  [ 4 ]
Total Votes : 17

Indeed, I didn't know about xrange(), just range(). Useful little tidbit to know.
For those who want type safety in Python, you can always do something like this:


Code:
def Filter(*types):
    def wrapper(func):
        def check(*args):
            assert len(types) >= len(args)
            for i in range(len(args)):
                assert isinstance(args[i], types[i])
            return func(*args)
        return check
    return wrapper

@Filter((int,long), int)
def Add(a, b):
    return a + b


Try to pass in anything but an int or long for the first argument, or anything but an int for the second argument, and it will throw an assertion error. The Filter should, as far as I know, work for any type - user defined or built in, it shouldn't matter Smile
Oooh, that's a pretty nice piece of code. It seems to me, though, that if you're using such a filter you're probably being careful enough to avoid automatic recasting anyway.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 2 of 2
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement