Click here to Skip to main content
15,888,351 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Confused by team mate... Pin
honey the codewitch21-Jul-20 17:15
mvahoney the codewitch21-Jul-20 17:15 
GeneralRe: Confused by team mate... Pin
Super Lloyd21-Jul-20 18:40
Super Lloyd21-Jul-20 18:40 
GeneralRe: Confused by team mate... Pin
Richard MacCutchan21-Jul-20 21:47
mveRichard MacCutchan21-Jul-20 21:47 
GeneralRe: Confused by team mate... Pin
honey the codewitch22-Jul-20 4:54
mvahoney the codewitch22-Jul-20 4:54 
GeneralRe: Confused by team mate... Pin
Richard MacCutchan22-Jul-20 5:04
mveRichard MacCutchan22-Jul-20 5:04 
GeneralRe: Confused by team mate... Pin
Dave Kreskowiak21-Jul-20 17:32
mveDave Kreskowiak21-Jul-20 17:32 
GeneralRe: Confused by team mate... Pin
Super Lloyd21-Jul-20 18:34
Super Lloyd21-Jul-20 18:34 
GeneralRe: Confused by team mate... Pin
Jon McKee21-Jul-20 19:46
professionalJon McKee21-Jul-20 19:46 
Hmmmm...
1) FilterQueue but takes a List? Why not just name it Filter (for both)? The parameter gives you more consistent meaning in the face of changes.
2) For loop but never uses the iterator variable? I know here it's used to lock-in the initial size so re-enqueueing doesn't cause infinite recursion but it just looks bad imo. Could easily be made to use a while loop.
3) Dequeue in both if-else blocks but uses Peek for the test case anyways?

Example fix for #1-#3:
C#
static void Filter(List<Foo> list)
{
    Queue<Foo> queue = new Queue<Foo>(list);
    list.Clear();
    Foo item = null;
    while (item = queue.Dequeue())
    {
        if (!Remove(item))
            list.Add(item);
    }
}

Still not great as you no doubt know. It unnecessarily involves the Queue and complicates the code for no gain over the original list-only code. If I was to offer something that imo looks "cleaner" it would be:
C#
static void Filter(List<Foo> list) =>
    list.RemoveAll(item => IsRemovable(item)); //I agree with Dave on IsRemovable over Remove.
But that's just a personal preference.

EDIT: A word to clarify.

modified 22-Jul-20 1:57am.

GeneralRe: Confused by team mate... Pin
Super Lloyd21-Jul-20 19:50
Super Lloyd21-Jul-20 19:50 
GeneralRe: Confused by team mate... Pin
Jon McKee21-Jul-20 19:55
professionalJon McKee21-Jul-20 19:55 
GeneralRe: Confused by team mate... Pin
Super Lloyd21-Jul-20 20:13
Super Lloyd21-Jul-20 20:13 
GeneralRe: Confused by team mate... Pin
David O'Neil21-Jul-20 20:26
professionalDavid O'Neil21-Jul-20 20:26 
GeneralRe: Confused by team mate... Pin
Super Lloyd21-Jul-20 20:34
Super Lloyd21-Jul-20 20:34 
GeneralRe: Confused by team mate... Pin
Jon McKee21-Jul-20 20:50
professionalJon McKee21-Jul-20 20:50 
GeneralRe: Confused by team mate... Pin
David O'Neil21-Jul-20 21:05
professionalDavid O'Neil21-Jul-20 21:05 
GeneralRe: Confused by team mate... Pin
F-ES Sitecore22-Jul-20 1:31
professionalF-ES Sitecore22-Jul-20 1:31 
GeneralRe: Confused by team mate... Pin
Jon McKee22-Jul-20 9:21
professionalJon McKee22-Jul-20 9:21 
GeneralRe: Confused by team mate... Pin
F-ES Sitecore23-Jul-20 0:30
professionalF-ES Sitecore23-Jul-20 0:30 
GeneralRe: Confused by team mate... Pin
Jon McKee23-Jul-20 12:33
professionalJon McKee23-Jul-20 12:33 
GeneralRe: Confused by team mate... Pin
Johnny J.21-Jul-20 21:22
professionalJohnny J.21-Jul-20 21:22 
GeneralRe: Confused by team mate... Pin
OriginalGriff21-Jul-20 20:00
mveOriginalGriff21-Jul-20 20:00 
GeneralRe: Confused by team mate... Pin
Super Lloyd21-Jul-20 20:12
Super Lloyd21-Jul-20 20:12 
GeneralRe: Confused by team mate... Pin
OriginalGriff21-Jul-20 20:14
mveOriginalGriff21-Jul-20 20:14 
GeneralRe: Confused by team mate... Pin
Super Lloyd21-Jul-20 20:35
Super Lloyd21-Jul-20 20:35 
GeneralRe: Confused by team mate... Pin
Super Lloyd21-Jul-20 20:38
Super Lloyd21-Jul-20 20:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.