« first day (484 days earlier)      last day (3532 days later) » 

9:18 PM
When you write a Brainfuck interpreter in Java, does that become ?
 
BrainCaffeine
 
TTGTB
 
0
Q: Brainf**k Interpreter in Java

Simon André ForsbergDescription To increase the awareness of my previous brainfuck question, not only is there a bounty on it (Thanks, Mat's Mug) but here's also a brainfuck interpreter. This is written with Java 8 Class Summary (298 lines in 4 files, making a total of 7409 bytes) BrainF.java: Represents a Brai...

 
^^ Working my way towards the Socratic badge
 
@Mahir I am here now...
 
9:25 PM
@nhgrif So should I repaste my original set of questions?
 
Not all of them, just ask them one at a time. Ask one, let me answer, ask any questions about my answer, then move to the next one.
I don't remember the questions though.
 
Try to be in chat sometime when I'm in there so we can have a discussion. — nhgrif 3 hours ago
oops hold on
 
lol
 
that's weird, it's not letting me paste the link to the original question
3
Q: Should this Method be in TableViewCell or ViewController?

MahirI have a custom tableview cell for displaying different foods, with a star next to each name. If the food has been favorited (i.e., it exists in the database), the star is filled in, otherwise it is empty. I'm not sure if the logic that determines the color of the star should go in the view cont...

So in cellForRowAtIndexPath do I retrieve the corresponding data object and call setIsFavorited:?
 
You call setIsFavorited: on the UITableViewCell subclass.
 
9:29 PM
New user, first answer, seems to be a good one:
2
A: How to decouple tests from implementation and increase their resilience?

KirschsteinWithout trying to sound tautological, the tests in your original question are coupled to your implementation because that's exactly what they are testing. You're testing that - Remove is called on a database abstraction The method doesn't throw an exception for an invalid slug The method retu...

 
MyDataObject *currentRow = self.myDataArray[indexPath.row];

cell.isFavorited = currentRow.isFavorited;
 
ok, that's what I thought
so the second question: when the star is tapped, it triggers a function in the cell through IBAction
 
And this is different from didSelectRowAtIndexPath:?
 
yes, didSelectRow is a function in my tableviewcontroller
I have a separate class for the tablevewcell
 
@sim you're welcome!
 
9:34 PM
so
@interface MenuCell : UITableViewCell

@property (nonatomic, retain) IBOutlet UIButton *favButton;
@property (nonatomic, retain) IBOutlet UILabel *foodLabel;
@property (nonatomic, assign) StarState currentState;

- (IBAction)registerFavorite:(id)sender;
- (BOOL) isStarredForName:(NSString*)foodName;
-(void)changeStarToState:(StarState)state;
@end
when the star is tapped, registerFavorite: is called
 
In this case, instead of the above snippet I showed you, you might want something more like this:
cell.dataObject = self.myDataArray[indexPath.row];
Where you pass the cell the entire data object.
And registerFavorite: now calls [self.dataObject toggleFavorite];
(as well as updating the star ui)
 
0
Q: Is this an appropriate method of organising model methods?

Luke AshfordApologies in advance if this is off-topic/not ideal for CR, but I feel it goes best here than on SE or Programmers. I've recently started using Laravel and have created a simple blog application, with a few bells and whistles. As my models where becoming a little cluttered with different methods...

 
Ok, so do I still need to reload the tableview data
 
You mean, [self.tableView reloadData];?
 
yeah
 
9:42 PM
It's not strictly necessary when the cell updates its own UI.
 
ok, so then the purpose of creating the data array is to determine the initial state of each cell when you load the cells in the tableview?
 
@CaptainObvious @Jamal, I think you should have chosen the "real code" off-topic for that one
 
The purpose of creating the data objects is to separate the business logic from the UI logic.
 
@nhgrif He wants the comments reviewed
And reviewing design is not off-topic!
His question however, is off-topic
 
The purpose of creating the array of these objects is that is by far the easiest way to deal with them in a tableview.
@SimonAndréForsberg Even if he intends for the comments to be the focus, there's nothing concrete there. He still needs to include the actual comments as well as the code the comments belong to
 
9:47 PM
@nhgrif He just wants the style of his comments reviewed though. The way he uses comments to separate sections. In the end I agree though, this is not a code review question.
 
We should probably open a meta for this.
 
I feel that it is off-topic, I just can't put my finger of exactly why
Is comments real code?
 
Which is why we should open a meta for it.
 
I feel that it is not real code
 
Ok, so I had used the function isStarredForName: within the cell to determine the original state of each cell
 
9:48 PM
Comments can absolutely be reviewed Simon.
Need I remind you:
26
A: How could I optimize this script?

nhgrifThis script is a total of 99 lines. Of that, 49 lines are insulting, annoying, and ironic self-congratulating comments. In general, comments are good. They help any future maintainer (including yourself when it's been 6 months since the last time you looked at the script) to understand what ...

 
to initialize the data array, do I need to move this function to my vc?
 
@Mahir You don't need to worry about the original state of the cell. The cell should always visually reflect whatever data the data object contains.
 
in Game Development, 4 mins ago, by hichris123
@OutlawLemur There's always Code Review. :P
 
You shouldn't initialize the data array from the cells. You should initialize the cells based on the data array.
 
I'm recruiting people for ya. :)
 
9:50 PM
Right, maybe I should rephrase the question I have
 
Hooray! I anticipate a flood of Flappy Bird clones to review!
 
lol
2
 
when I initially load the cells, some of them will have filled in stars, while others will have empty stars
when i create my dataObject array, I need to know which objects need what state
 
Yes, but how do you determine which are which?
You're still looking at it backwards.
 
Current list in the queue is: Salesforce, Expression Engine, Anime, Computer Science, Japanese, Cryptography, Movies, Blender, and English Language Learners. — Grace Note ♦ Aug 6 at 0:13
 
9:51 PM
- (BOOL) isStarredForName:(NSString*)foodName {

PFInstallation *installation = [PFInstallation currentInstallation];
NSArray *foodList = (NSArray*)[installation objectForKey:@"favorites"];
return ([foodList containsObject:foodName]);
}
 
It's going to be a while for you to graduate. :(
 
(You probably shouldn't call the class DataObject by the way... that's just my placeholder example name)
 
yeah lol
 
That method needs to be completely rethunk
What's PFInstallation?
 
but anyways, I use a website called parse.com to store a list of all the favorited fooods for each user
 
9:52 PM
@nhgrif Good point. That one has the context of real code though.
 
You need to use PFInstallation to create an array of these data objects.
 
so what I'm doing right now is passing the name of the food to the function and checking if it exists in the database
 
@hichris123 You should recruit yourself!
 
Right, that's going about it the wrong way.
I'm not completely familiar with Parse, but I get the gist.
What properties about the food do you need to know?
 
just the name
 
9:54 PM
The food name, whether or not it's favorited?
 
@hichris123 As long as we'll survive, I'll survive...
 
I mean throughout the entirety of your app--not just this table.
 
oh, are you talking about the function or my app in general
 
Right.
 
ok
 
your DataObject class should hold all of the properties you ever need to know about this food object. It's name, whether or not it's a favorite, ingredient list, instructions, dietary information, etc., etc., etc.
 
so...the name of the food, whether it's favorited, whether it's vegetarian, and a link to the nutrition info
 
Why aren't those pretty tags enabled in all rooms?
 
ok, so I already have a MenuItem class that has a isVegetarian property and a link property
 
@SimonAndréForsberg I dunno. They're only enabled on Meta Stack Exchange chatrooms, as far as I know.
 
9:56 PM
and a name property of course
 
@Mahir Right, exactly. So you run your Parse query before you load your table view. Based on the results of the query, you create an array of these MenuItem objects.
And now you're ready to show your table view based on the data in that array.
 
But the data in the table isn't the same as the data in the query --
 
How so?
 
the app displays the current set of foods being served in the dining halls on a particular day
 
You can't write a query to grab that specific information?
Or is that information something that could be included as part of your MenuItem class?
Couldn't your MenuItem objects have an array property which contains NSDate objects representing upcoming serve times?
 
9:58 PM
so maybe I should backup a few steps
 
Yup.
It seems like a lot of work... but once you get this base layer down and down properly, the entirety of the app should seem simpler to work with and deal with, and extending your app in the future will be easier.
In the end, you want to just be passing these MenuItem objects to and fro.
 
Are you a student at UCLA?
 
I scrape the data off this webpage and store each food in a MenuItem object, along with vegetarian info and whatever
yes I am
 
I would highly recommend trying to get in touch with whoever runs that website and request they add a webservice that will hand you that data in JSON format.
 
10:02 PM
ok, I'll try to do that. but in the meantime,
Once I fetch the data from the server, I pass an array of the MenuItem objects to the tableviewcontroller
 
Yes.
 
these MenuItem objects represent the foods currently on the menu, independent of the whole favorite thing
 
0
Q: Are my one-method (and a couple attribute) classes overkill?

Nick TI saw a talk by Jack Diederich a few weeks ago titled "Stop Writing Classes" and noticed that some of my code perhaps echoes what he argues against (to the effect of "classes with two methods, one of which is __init__") in my code. For some parser that needed to run through a bunch of data, I cre...

0
Q: This code is for cycling time trials

TimIt would be helpful to know where I could improve the style of it, so it follows the style guide better, and also any ways I could compact it - especially at the end, where I have added items to a list then removed them - is there a more elegant way to do that? def reptillint(sentence,mini,maxi,...

 
Right.
CAPTAIN SPAMVIOUS
 
^^lol
anyways
 
10:04 PM
I would assume the default state of favoriteness should be not-a-favorite
 
what I was planning on doing was something along the lines of
well, for a brand new user that's the case
but let's say for example, you favorite guava pizza on Wednesday
 
Okay, so... you use a Parse database to keep track of user's favorited status?
 
and 3 weeks later, guava pizza reappears on the menu
then guava pizza should be already starred upon opening the app
 
In that case, the MenuItem class should take care of fetching the information about whether or not this object is a favorite.
So, scrape the website, instantiate the menu item objects.
After instantiating the menu item objects, call a method (on all of them) to have them go check Parse on their own
And based on the result of that query, they set their own isFavorite property.
So not in the cell, and not in the tableviewcontroller, but in the MenuItem object.
 
ok, that makes much more sense
 
10:09 PM
A Parse database may be overkill though. You could probably do this with NSUserDefaults pretty easily.
The one advantage you get with a Parse database is that you could maintain a user's favorites without using iCloud and even cross-platform.
 
I could, but I use the favorites to send push notifications to users when their favorites appear on the menu
 
Ah, that makes sense.
 
also, instead of passing just the favorite property from the MenuItem to the cell
should I just pass the entire MenuItem
because I also set the text color to green if the food is vegetarian
and I determine the text of each cell based on the name property of MenuItem
actually nm, all that should still take place in didSelectRowAtIndexPath in the view controller
 
None of that needs to happen in didSelectRowAtIndexPath:.
You could pass all of that individually (property by property) in cellForRowAtIndexPath:
But because you allow them to toggle favorites, you might pass the entire MenuItem object to the cell.
 
yeah sorry I got the method names mixed up
well, what I have is something like
MenuItem* food = .....

cell.foodLabel.text = food.name;

if (food.isVegetarian || food.isVegan)
cell.foodLabel.textColor = ....
and then I was just going to add

cell.isFavorited = food.isFavorited
 
10:16 PM
That would be fine, but then you have to figure out how to deal with the user marking it as a favorite.
 
ok so instead should I just pass the whole MenuItem object
 
That'd be okay.
 
cell.data = food;
[cell setIsFavorited:food.isFavorited];
 
Nope.
cell.data = food; yes, but then...
Although, data is probably a bad name... but you'll want to add this method to your cell:
- (void)setData:(MenuItem *)data {
    _data = data;

    // set up all of the cell's IBOutlets based off data passed in
}
 
ok, so just override the setter?
 
10:22 PM
Yep.
But make sure to include _data = data; line
and let the setter set all of the cell's UI elements.
 
ok that makes sense
last question
what was the inherent problem with my initial approach
you mentioned I was giving the cell and vc too much responsibility
and that I was wasting time reconstructing each cell
I still don't understand the latter point completely
 
You said this:
> Currently, I have this in the view controller under didSelectRowForIndexPath:
And then posted a code snippet which referenced cell
Which means you did [tableView cellForRowAtIndexPath:indexPath]; in didSelectRowForIndexPath:, correct?
 
Sorry, I didn't mean didSelectRowForIndexPath:
I meant cellForRowAtIndexPath
I keep getting the names mixed up
 
Oh, well then nevermind that comment.
 
but the rest of the changes still apply, right
 
10:29 PM
But basically, you should never call [tableView cellForRowAtIndexPath:indexPath]
Yes, the rest of the changes still apply.
You tagged your question with .
The UITableView and the UITableViewCell both represent the v of . They're the view aspects.
The UIViewController or UITableViewController represent the c of . They're the controller aspects.
 
and MenuItem is the model right
 
Right. But it's incomplete.
Because part of the data model is accessed by the views directly talking to parse.
Instead, whether or not a MenuItem is favorited should be a property of the MenuItem.
Because then, no matter how many views you want to display information about a menu item, all the code for determining whether or not a menu item is favorited and all of the code for toggling it as a favorite, all of that code is all in one central location.
 
and is cell.menuItem a better name than cell.data?
 
Yep.
Particularly if the class is called MenuItem
 
Alright, thanks for all the help. I should be good for now
 
10:37 PM
When I see a variable or property called data, I expect it to either be an NSData, NSMutableData, or an C-array of bytes (char, or unsigned ints or whatever).
 
I have an entirely separate question that I'll need to post on code review pretty soon, and since I feel like the same 2-3 people answer all my questions, I'll probably talk to you again soon
alright, I'll try to start making my variable names more clear. Thanks
 
10:51 PM
0
Q: RESTful API for Todos using Hapi

jrmceMy goal is to create a simple restful api that will be accessed by an AngularJS front end. Even though it's fairly simple, I'd like understand how to make it more reliable, secure, and best-practices compliant. The whole api is contained in a single file, I'm not overly concerned about organizati...

 
11:39 PM
Hmm... 13 of the projects in my Eclipse workspace are related to Minesweeper... perhaps it's time to give Minesweeper its own workspace?
5
 

« first day (484 days earlier)      last day (3532 days later) »