From the course: Python Data Science Mistakes to Avoid

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Creating circular dependencies

Creating circular dependencies - Python Tutorial

From the course: Python Data Science Mistakes to Avoid

Start my 1-month free trial

Creating circular dependencies

- [Instructor] When you're programming, it's important to avoid the mistake of creating circular dependencies. Circular dependencies make it hard to maintain code in the long run, reduce code reusability, and can cause errors. For example, let's say I wrote this program here. I defined four functions, after which I called the function rug_dim, which is supposed to select the dimensions for a rug in feet and display them. Note that in the definition of rug_dim width is determined by calling the function getWidth. Which generates and returns a random width. And length is determined by calling the function getLength. Now, in the definition of getLength, the function chooseLength is called. And in the definition of chooseLength, getLength is called. This indicates a circular dependency. I'll run this cell now to show you what happens. As you can see, I got a RecursionError. This is due to the circular dependency between the…

Contents