|
|
| Programming Discussions about computer programming |
08-23-2011, 10:46 AM
|
#1231
|
|
veteran
Join Date: Feb 2006
Location: Brooklyn
Posts: 2,444
|
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
Gullanian, what was your role with that site/software? Looks like a fun project..
|
|
|
08-23-2011, 10:52 AM
|
#1232
|
|
Carpal \'Tunnel
Join Date: Apr 2005
Location: Shallow End OTKP
Posts: 13,973
|
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
i have ~no concrete experience but i've been planning to add puppet to the mix at work for a while now. by all accounts puppet is awesome and well worth the investment.
my research suggests that puppet > chef unless you're in a select minority of users who think it's really important that the configuration language be more like real ruby and less like a DSL. puppet has a longer history and a larger user community than chef.
|
|
|
08-23-2011, 11:04 AM
|
#1233
|
|
Carpal \'Tunnel
Join Date: Dec 2006
Location: London
Posts: 13,044
|
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
Quote:
Originally Posted by redCashion
Gullanian, what was your role with that site/software? Looks like a fun project..
|
Thanks! I just do the website/admin side of things mainly at the moment, my brother writes the actual software. Just the two of us! It is good fun working on it, the users are all great and it's fun to see what people make. I do want to learn C++ at some stage so I can help, I do plan on writing lots of Javascript plugins for it soon though.
|
|
|
08-23-2011, 11:28 AM
|
#1234
|
|
Carpal \'Tunnel
Join Date: Oct 2004
Location: taking notes on u (see profile)
Posts: 11,993
|
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
Quote:
Originally Posted by Gullanian
Thanks! I just do the website/admin side of things mainly at the moment, my brother writes the actual software. Just the two of us! It is good fun working on it, the users are all great and it's fun to see what people make. I do want to learn C++ at some stage so I can help, I do plan on writing lots of Javascript plugins for it soon though.
|
i think this is especially impressive given it's a 2 man project. nice work. how long did it take you guys?
|
|
|
08-23-2011, 06:23 PM
|
#1235
|
|
old hand
Join Date: Oct 2008
Location: old school online player
Posts: 1,263
|
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
When you hover over the "About Us" tab, the help says "About Scirra and it's game making history." Change "it's" to "its" imo. I'm listening to the funky music now.
|
|
|
08-24-2011, 06:14 AM
|
#1236
|
|
Carpal \'Tunnel
Join Date: Dec 2006
Location: London
Posts: 13,044
|
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
Thanks for typo will fix  Website I've been doing for a few months. It's been hard though b/c I'm full time web dev at work 9am-6pm so coming home at 7pm and then doing 3 hours more of the same sort of work is kind of crushing, I wouldn't recommend it. Down to 3 days a week at work now so should improve and get more done. Loads more to do on it.
My brothers spent about 6 months to date writing Construct 2 I think, probably around the same amount of time left until it's full release. His other one Construct Classic he started writing when he was 16 I think, had around 500,000 downloads to date! Construct 2 should be more popular and all round better.
|
|
|
08-24-2011, 10:56 AM
|
#1237
|
|
Carpal \'Tunnel
Join Date: Dec 2006
Location: London
Posts: 13,044
|
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
Anyone think of a good way to make this more concise? It seems like duplicate code to me although it is simple, it feels ugly having it:
Code:
/// <summary>
/// Is a group in the basket already?
/// </summary>
public static bool isItemInBasket(List<BasketItem> BasketItems, int GroupID)
{
foreach (BasketItem B in BasketItems)
{
if (B.GroupID == GroupID)
return true;
}
return false;
}
public static bool isItemInBasket(List<BasketItem> BasketItems, int GroupID, DateTime ArtworkDate)
{
foreach (BasketItem B in BasketItems)
{
if (B.GroupID == GroupID && B.ArtworkDate == ArtworkDate)
return true;
}
return false;
}
|
|
|
08-24-2011, 11:21 AM
|
#1238
|
|
Pooh-Bah
Join Date: Jan 2005
Location: Belligerent and numerous
Posts: 5,213
|
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
You can make a private method that takes the list and a delegate that takes in a BasketItem and returns a bool. The body is all the duplicated code, but the if clause just calls the delegate method. The two methods you have now become wrappers for the private method and pass in a lambda expression or declared method that performs the specific boolean expression.
|
|
|
08-24-2011, 11:34 AM
|
#1239
|
|
adept
Join Date: Apr 2010
Location: Deep end of the player pool
Posts: 733
|
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
Seems like that would increase the complexity of the code with very little benefit
|
|
|
08-24-2011, 11:35 AM
|
#1240
|
|
Carpal \'Tunnel
Join Date: Oct 2004
Location: taking notes on u (see profile)
Posts: 11,993
|
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
Quote:
Originally Posted by Gullanian
Anyone think of a good way to make this more concise? It seems like duplicate code to me although it is simple, it feels ugly having it:
Code:
/// <summary>
/// Is a group in the basket already?
/// </summary>
public static bool isItemInBasket(List<BasketItem> BasketItems, int GroupID)
{
foreach (BasketItem B in BasketItems)
{
if (B.GroupID == GroupID)
return true;
}
return false;
}
public static bool isItemInBasket(List<BasketItem> BasketItems, int GroupID, DateTime ArtworkDate)
{
foreach (BasketItem B in BasketItems)
{
if (B.GroupID == GroupID && B.ArtworkDate == ArtworkDate)
return true;
}
return false;
}
|
Yeah I don't like it. The Thug's idea is pretty good, but I'd prefer to create a class wrapping your List<BasketItem>, call it BasketItems. Now these two search methods become instance methods of this class rather than generic static methods, and they will require 1 less argument when you call them. It will also be easy to remove the duplicate code this way. And you can also abstract out the process of putting conditions on the list items to search for, in case you are planning to add even more variations on this method. That is, BasketItems could have a addSearchCondition method or something like that. Or the search conditions could themselve be made an object, etc. This part may be overkill for your current dillema.
|
|
|
08-24-2011, 11:44 AM
|
#1241
|
|
Carpal \'Tunnel
Join Date: Jul 2006
Posts: 11,412
|
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
Code:
/// <summary>
/// Is a group in the basket already?
/// </summary>
public static bool isItemInBasket(List<BasketItem> BasketItems, int GroupID)
{
return isItemInBasket(BasketItems, GroupID, null);
}
public static bool isItemInBasket(List<BasketItem> BasketItems, int GroupID, DateTime ArtworkDate)
{
foreach (BasketItem B in BasketItems)
{
if (B.GroupID == GroupID && (ArtworkDate == null || B.ArtworkDate == ArtworkDate)
return true;
}
return false;
}
Not sure if I actually like it, but I don't like overloaded methods having different bodies.
Edit: I like it better than creating a BasketItems class. I think wrapping generic concepts can often be a huge pain in the ass because you end up having to pass through more and more features as you use it in more and more places.
|
|
|
08-24-2011, 11:45 AM
|
#1242
|
|
Carpal \'Tunnel
Join Date: Oct 2004
Location: taking notes on u (see profile)
Posts: 11,993
|
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
jj, your solution is perfect if he doesn't want to do any refactoring at all.
|
|
|
08-24-2011, 11:48 AM
|
#1243
|
|
Carpal \'Tunnel
Join Date: Apr 2005
Location: Shallow End OTKP
Posts: 13,973
|
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
shabby's solution is what i thought of if the language in question (javascript?) doesn't support default args.
if the language does support default args, then i'd collapse those methods into one with this signature:
Code:
public static bool isItemInBasket(List<BasketItem> BasketItems,
int GroupID, DateTime ArtworkDate = null)
|
|
|
08-24-2011, 11:49 AM
|
#1244
|
|
Carpal \'Tunnel
Join Date: Jul 2006
Posts: 11,412
|
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
Quote:
Originally Posted by gaming_mouse
jj, your solution is perfect if he doesn't want to do any refactoring at all.
|
I'm not sure what you mean. What other refactoring would you do?
Edit:
Removed my totally wrong assumption about the language...
|
|
|
08-24-2011, 11:51 AM
|
#1245
|
|
Carpal \'Tunnel
Join Date: Dec 2006
Location: London
Posts: 13,044
|
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
jj that's basically what I was thinking of doing as well, it's definitely an improvement over what I posted.
Also like other ideas posted but seems slightly over complicated for this, but the lamdba/linq idea is a good one. You can reduce both functions to one liners like:
Code:
/// <summary>
/// Is a group in the basket already?
/// </summary>
public static bool isItemInBasket(List<BasketItem> BasketItems, int GroupID)
{
return (from c in BasketItems where c.GroupID == GroupID select c).SingleOrDefault() != null;
}
public static bool isItemInBasket(List<BasketItem> BasketItems, int GroupID, DateTime ArtworkDate)
{
return (from c in BasketItems where c.GroupID == GroupID && c.ArtworkDate == ArtworkDate select c).SingleOrDefault() != null;
}
I think that's probably best
Edit: This is ASP.net/C#
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -4. The time now is 02:45 PM.
|