Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7698351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:13:17+00:00 2026-05-31T22:13:17+00:00

EDIT: When should and shouldn't you break away from OOP for speed/performance? might be

  • 0

EDIT: When should and shouldn't you break away from OOP for speed/performance? might be relevant to this question.

I’m sorry if my question is unclear; I’m an amateur hobbyist and, were I better educated, I might know some relevant jargon to be more specific. Allow me to use some simple example code.

class EmployeeRecords(object):
    """A record of all employees."""
    def __init__(self):
        super().__init__()
        self.employees = []
        # The following two attributes are redundant.
        self.at_office = {"LAN":[], "DET":[], "KAL":[]}
        self.in_thirties = []

    def register_employee(self, employee):
        """Register a new employee in the records.

        This entire method is redundant.

        """
        self.employees.append(employee)
        self.at_office[employee.office_code].append(employee)
        if 30 <= employee.age < 40:
            self.in_thirties.append(employee)

class Employee(object):
    """An employee record featuring relevant information for queries."""
    def __init__(self, first_name, last_name, age, office_code):
        super().__init__()
        self.first_name = first_name
        self.last_name = last_name
        self.age = age
        self.office_code = office_code


# Instantiation and what-not goes here.
...

print([x for x in my_records.employees if 30 <= x.age < 40])
# VS
print(my_records.in_thirties)

Which is more appropriate? Is the latter method generally considered to be bad form by the experts as SO?

–More Info–

It seems like it might be computationally more effective to just add Employee instances to relevant lists upon registration in the EmployeeRecords. However, I’ve been recently studying SQL (finally), and it seems that a big part of using it effectively is ‘data normalization’: removing redundant data from multiple tables that could be otherwise attained by a deeper query.

I can see how and agree that having redundant data can invite bugs; why bother keeping all of these redundant lists updated when my queries can pull from a single list through object (or, in SQL’s case, table) association? In the above example, the list comprehension will always return the correct information, but using my_records.in_thirties would yield unexpected results if I foolishly appended my_records.employees instead of using my_records.register_employee.

This is just an example where, in terms of code management and performance, there’s little difference between either method. In practice, though, a query could involve searching through lists within lists of objects whose attributes are lists that need to be queried for other objects.

Is it considered to be good practice to avoid redundant lists for this purpose, or would it be considered by most to be favorable to repeatedly doing very deep searches? I understand that Python is not SQL, but I think that OOP is very much about the relationships between objects through the use of attributes, and so I can see how these sorts of lists would be considered bad form and prone to bugs.

Thanks for your help. I have no formal education and, although I have years of programming experience with pet projects, I’m always learning new things in the way of effective architecture. This is my first post on SO after years of browsing it, so please be gentle if this is a dumb or inappropriate question. I don’t know where else to turn!

-David Hernandez

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:13:19+00:00Added an answer on May 31, 2026 at 10:13 pm

    Basically it depends on how often you need a particular thing versus how often you need what it’s based on.

    If the only query you ever make about Employees is which ones are in their thirties, and you’re running into performance issues making that query, then it makes sense to compute it ahead of time.

    If, on the other hand, that’s only one of many queries you’re making, it makes less sense to clutter your data models with tons of precomputed things; keeping the models simple and computing+caching what you need when you need it will make your code much easier to work with.

    Only optimize for performance what you need to optimize for performance, if doing so would come at the cost of maintainability/coding time. (See http://c2.com/cgi/wiki?PrematureOptimization.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[EDIT] Hmm. Perhaps this question should be titled what is the default user-input dialog
within my App it should be forbidden to edit (customize) the TabBar. This means
Edit: I am using SqlDataAdapters to fill the data sets. Sorry--I should have been
Edit: This question was written in 2008, which was like 3 internet ages ago.
Edit: From another question I provided an answer that has links to a lot
EDIT: This question is more about language engineering than C++ itself. I used C++
This is an IDE question for Visual Basic 2008 Express Edition. It might be
EDIT: Duplicate of Should Entity Framework Context be Put into Using Statement? I've been
EDIT: I suppose I should clarify, in case it matters. I am on a
EDIT: This was formerly more explicitly titled: - Best solution to stop Kontiki's KHOST.EXE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.