Fix Sort Bug: Company Add Resets Order
Hey guys, let's dive into a bug we've uncovered in our tester, PE-D Tester C, specifically affecting the sorting functionality. It seems that when you add a new company, it unexpectedly resets the sort comparator back to the default 'name' sort, even if you had previously sorted by something else, like the deadline. This can be a real pain, especially if you're managing a lot of applications and rely on a specific sort order to keep things organized. We'll break down the issue, show you exactly how it happens, and discuss the impact and a potential fix.
Understanding the Sorting Bug
So, what exactly is happening here? We've identified a feature flaw where the act of adding a new company entry causes the application's sort order to revert to sorting by name. This is happening even when the user has explicitly chosen a different sorting criterion, such as sorting by the deadline. Imagine you've carefully sorted all your job applications by their closing dates to prioritize your efforts, and then you go to add a new one. Instead of keeping your deadline-sorted list intact, the system throws it all out of whack and sorts everything alphabetically by company name. This is definitely not ideal and can lead to confusion and wasted time trying to re-establish the desired order.
Steps to Reproduce the Issue
Let's walk through how you can easily replicate this bug yourself. It's pretty straightforward and highlights the problem clearly. You'll need to follow these simple steps:
-
Add several applications: Start by populating your application list with a few entries. For example, you can use commands like:
add n/Google i/Technology a/SWE t/Test e/test@google.com s/Saved d/2024-12-31 add n/Microsoft i/Technology a/PM t/Test e/test@microsoft.com s/Applied d/2024-11-30This gets us a couple of applications in the system.
-
Sort by deadline: Now, tell the system to sort your applications by their deadlines. You'd use the command:
sort deadlineAt this point, your applications should be neatly ordered from the earliest deadline to the latest.
-
Add a new application: The crucial step! Add another application to the list. Let's say you add:
add n/NewCompany i/Technology a/SWE t/Test e/test@new.com s/Saved d/2024-10-15
What you'll observe (The Actual Behavior):
After performing step 3, you'll notice that the list is no longer sorted by deadline. Instead, it has automatically reset to sort alphabetically by company name. This is the core of the bug.
What You'd Expect (The Expected Behavior):
Ideally, after adding a new application, the existing sort order should be maintained. If you sorted by deadline, the new application should be inserted into the correct position within that deadline-sorted list, and the overall sort by deadline should persist. The expected output would be the list still sorted by deadline, with 'NewCompany' placed appropriately according to its October 15th deadline.
Visual Evidence of the Bug
To further illustrate the problem, we have included two screenshots. The first image shows the application list before adding the new company and after sorting by deadline. You can clearly see the order is based on the deadline. The second image, taken after adding 'NewCompany', demonstrates the unexpected reset. The list is now sorted alphabetically by name, proving the bug in action. These visuals confirm that the sorting preference is indeed being lost.
Impact of the Sorting Issue
This sorting bug, while seemingly minor, can have a significant impact on user experience, especially for those who are actively managing multiple job applications. When the sort order resets unexpectedly, users lose their carefully curated view of their applications. If you're relying on a deadline sort to manage your application process, this reset means you have to manually re-sort every time you add a new entry. This is not only disruptive to your workflow but also increases the chance of missing important deadlines if your prioritized list is no longer visible. For power users or those with many applications, this repetitive task can become a major annoyance and a drain on productivity. It undermines the reliability of the application management tool, as users can no longer trust that their chosen sort order will be maintained.
Suggested Fix for the Comparator Reset
To address this frustrating bug, we propose a straightforward fix that should restore the expected behavior. The core idea is to ensure that the application's sorting mechanism remains consistent after adding new entries. Here's the suggestion:
Preserve the Current Comparator: The most logical approach is for the application to remember the current sorting comparator that the user has set. When a new entry is added, instead of resetting the comparator to a default (like sorting by name), the system should simply re-apply the existing comparator to the updated list. This means if the user last sorted by deadline, the list should be re-sorted by deadline, with the new entry inserted in its correct place.
Alternatively, Only Re-sort Using the Existing Comparator: Another way to achieve a similar outcome is to ensure that any re-sorting triggered by adding an entry explicitly uses the currently active comparator. This prevents an implicit reset to the 'name' comparator. The system should be designed such that the add command, or the internal logic handling additions, respects the user's active sort preference.
By implementing one of these solutions, we can ensure that users maintain their preferred sorting order, significantly improving the usability and reliability of PE-D Tester C. This will prevent the disruption and potential for errors caused by the current comparator reset. It's about making the tool work for the user, not against them, by respecting their choices and maintaining a predictable interface.
We believe this fix is crucial for a smooth user experience. Keeping the sort order consistent after adding new applications is a fundamental expectation for any list management tool. This will allow users to manage their applications more efficiently and with greater confidence. Guys, this is a fix we can definitely implement to make our tool much better!