Strict mode?

J

Jack

While enjoying the dynamic feature of Python I find it difficult to refactor
code without breaking it. For example, if I modify a function to take more
arguments, or arguments of different types, I'll need to manually find out
all places where the function is called and make sure I modify them all,
unlike in C/Java, where the compiler will do the work of checking function
signatures, etc. I suppose there isn't a strict mode in Python. It would be
helpful though, when I don't need things to be so dynamic, and this is often
the case, when it comes to function arguments and return values, for
example. Even a module level or function level flag would be very helpful to
find broken code. Or, are there any third party tools that do this?
 
J

John Machin

While enjoying the dynamic feature of Python I find it difficult to refactor
code without breaking it. For example, if I modify a function to take more
arguments, or arguments of different types, I'll need to manually find out
all places where the function is called and make sure I modify them all,
unlike in C/Java, where the compiler will do the work of checking function
signatures, etc.

This specific problem can be addressed at least partially by setting
reasonable defaults for new arguments. This is a necessary technique
when the publisher of a language or a module/package wants to extend
the functionality of a function or method without introducing a new
name for the function/method.

The general problem is usually addressed in dynamic languages by
running a test suite.
 
L

Larry Bates

Jack said:
While enjoying the dynamic feature of Python I find it difficult to refactor
code without breaking it. For example, if I modify a function to take more
arguments, or arguments of different types, I'll need to manually find out
all places where the function is called and make sure I modify them all,
unlike in C/Java, where the compiler will do the work of checking function
signatures, etc. I suppose there isn't a strict mode in Python. It would be
helpful though, when I don't need things to be so dynamic, and this is often
the case, when it comes to function arguments and return values, for
example. Even a module level or function level flag would be very helpful to
find broken code. Or, are there any third party tools that do this?
> if I modify a function to take more
> arguments, or arguments of different types, I'll need to manually find out
> all places where the function is called and make sure I modify them all

This is not necessarily true. I add keyword arguments to functions quite
commonly and they don't affect any of the previously defined calls. If I do, a
good editor with search/replace seems to do the trick. I find it quite uncommon
to change the "types" of arguments, but when I do, I can use duck typing to work
around that as well. Hang in there, you will get it.

-Larry
 
N

Noah Dain

While enjoying the dynamic feature of Python I find it difficult to refactor
code without breaking it. For example, if I modify a function to take more
arguments, or arguments of different types, I'll need to manually find out
all places where the function is called and make sure I modify them all,
unlike in C/Java, where the compiler will do the work of checking function
signatures, etc. I suppose there isn't a strict mode in Python. It would be
helpful though, when I don't need things to be so dynamic, and this is often
the case, when it comes to function arguments and return values, for
example. Even a module level or function level flag would be very helpful to
find broken code. Or, are there any third party tools that do this?

Description: A refactoring tool for python
A framework and refactoring tool for Python. IDE Plugins are included for
Pymacs, IDLE and Vim. Using Bicycle Repair Man you can rename classes, methods
and variables, and all users of them are found and adjusted appropriately.
.
Homepage: http://bicyclerepair.sourceforge.net/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top