+1 (late, I know, I ran out of ammo early today!), but despite the upvotes, this is pretty much a SO-Style answer; on CR we prefer answers that review the OP's code - not necessarily long answers redacted in 2 hours, but while addressing OP's performance concerns (for example), consider commenting on any aspect of the code, including naming, formatting, best practices, etc. That said, welcome to soon-to-be-500 milestone! — Mat's Mug1 min ago
I'll be back in a little while, gotta be a dad right now ;)
@Jamal I answered it too. I didn't comment on global variables: global variables are no little different from making everything a data member of a Game class.
We probably get a lot of 'Game' questions, in which everything is a member of 'Game', where we don't say, "global: bad!" ... even though global data and members of a top-level class are more-or-less equivalent. IMO the 'OO' win in this question would be from 'encapsulating' smaller pieces: Ball, Paddle, etc.
I'm still not so keen with classes/OOP, so I didn't want to go too much into it. It would've taken some time to really tear apart that code and recommend the best path.
The current code solves the issue I had when trying to use property injection.
Problem: Every module must use constructor injection because of a circular reference that occurs when not using constructor injection with my factories and trying to use property injection
Reason: A module requires a...
I don't quite understand it either :/ ...Ninject works like any other IoC container (configure, compose, release) ..I'm not sure about the circular reference either. I do think there has to be a way to write this code "correctly" though.
I'm quite ashamed of not having been able to solidly tackle that one actually, it's right on my playground.
The idea is to move all usages of "new" to the composition root, which is ideally the app's entry point. By "injecting" dependencies in types' constructors, you get to "compose" the entire app's dependency graph at startup. The IoC container is just a tool that facilitates resolving the dependencies.
It literally forces your code to be testable and to follow all the principles of SOLID.
If you start breaking SRP you'll know because your constructor is going to start taking in 4, 5, 6 or more dependencies / "services".
If you push it all the way, you have full control over all dependencies across your entire application. Any class can be taken and tested with mock implementations of dependencies. TDD-enabled.
(I'm don't do TDD, but I find it nice that it's possible to do it that way)
we have a .......weird environment. 1 SQL Server instance with a 450GB production database, a copy for test & dev, another copy for replicating tons of XML data to the production database (the "model development and testing" database), and there's no room for another copy. We're all sharing the same instance and dev/test database.
I've seen that when Conway's Law is applicable, it implies the need for 'unit' tests before integration tests. And when unit tests are necessary then testing against mock dependencies may be necessary.
But (e.g. if the team is small) continuous integration and automated system testing can IMO be used instead of unit testing.
"Dependency Injection" seems to me (though I've barely read about it) to be a technique that's mostly for unit-testing.
we're rewriting a massive VB6 spaghetti monster in C#, I'm the one pushing for DI & testability. There's no documentation, the specs are unknown (will have to be inferreddecyphered from the broken code), and every change can break something else. Unit tests make a documentation for all those countless business rules.
So I've got a jquery project where I'm using an external class that has callback style events. Meaning, it has an "onSave" property that takes one function. However, I need to more than one other component to hook into it.
What I've settled on for now, goes like this:
var saveCallbacks = $.Call...
So I don't really pay too much attention to my profile all that much, but @syb0rg was commenting on his profile-views, and I went to look. What's suprising, is that I have apparently only been a member for 3 months.....
I have a producer consumer that simulates the interaction of threads controlling a hardware device.
I have 1 thread controlling the device, 1 thread reading, and 1 thread outputting. The read is synchronous on the thread while the controlling is asynchronous.
My producer is the thread contro...
#include <stdio.h>
#include <stdlib.h>
struct Stack {
int value;
int is_empty;
struct Stack *next;
};
int pop(struct Stack **stack) {
if ((*stack)->is_empty == 1) {
printf("Stack is empty!\n");
abort(); // not sure what this does
} else {
int value = (*stack)->value;
/...
Things you did well:
Overall the code looks very nice and well organized.
You used comments well.
Things you could improve:
Syntax:
typedef your structs.
struct Stack {
int value;
int is_empty;
struct Stack *next;
};
The typedef means you no longer have to write struct all over ...
Single app which listen to multiple RabbitMQ queue and process the message. Does this implementation is right or I am missing something.
//Message subscriber implementation
public class AuditSubscriber : IMessageSubscriber
{
public IList<string> SubscribedRouteKeys
{
...
Yeah, you're right. Your method was better. I just have to try to understand it more deeply so I can convert it to a matrix, and comment the block of code for clarity.
The user must enter x, y, and the limit. The program must find the multiples of these numbers that are below the limit that the user set themselves. The program adds up all the multiples and prints just that number at the end, and not all the multiples. For some reason it just isn't working for m...
It's weird how many people have birthday's in February. I'm sure it's just some kind of weird bias since mine is in February too, but I swear I've come across at least 9 trillion people with Feb birthdays recently.
And sometimes when there are other answers, I'm dissuaded from answering because I would have to explain what's wrong with the other answer, and blerh...
I tend to hover around C++ and PHP questions. Unfortunately a lot of C++ questions exceed my knowledge, and most PHP questions are either hopeless, already have a few answers that have terrible misinformation in them, or are too short to be meaningful.
PHP is not a pinnacle of question quality, I'm afraid :(
Things you did well:
Overall the code looks very nice and well organized.
You used comments well.
Things you could improve:
Syntax:
typedef your structs.
struct Stack {
int value;
int is_empty;
struct Stack *next;
};
The typedef means you no longer have to write struct all over ...
Actually saw that earlier, @syb0rg. Despite my lack of answering, I do very actively creep on what others are up to. Gotta vote. I want CR to graduate already :(.
Yeah, I thought about mentioning that earlier too, Yuushi. But... Laziness. And sickness. Which causes a terrible kind of laziness.
This is a framework for a json Parser I put together last night.
Any comments appreciated.
JsonLexer.l: Breaks the input into lexemes
JsonParser.y: Understands the language syntax
JsonParser.h: Header file to bring it all togeter
main.cpp: Test harness so it can be tested.
Makefile: S...
@syb0rg Fun fact: _t is reserved in POSIX :0. But I get what you mean. I'm sure they would just argue back something about just putting the struct instead of trying to be lazy with a two character suffix. Personally, I don't get their argument. I think really it comes down to opinion. After all, at the end of the day, it doesn't affect much. There is a certain value to struct in some situations. It's just redundant 99.9999% of the time.
November 15, 2013. 6:30AM UTC. Community Manager Grace Note posted How is Code Review doing right now?.
We are 100+ days later.
Rewind
Since mid-November 2013, a number of things have happened:
A fun tag was created on Meta-CR.
CR users answered the Call of Duty; incoming, as well as m...
I was inspired to come up with a record type which is flexible enough to handle various scenarios of versions. I was clever enough to come up with this...
type
TVersion = record
Values: array of Integer;
function Count: Integer;
class operator implicit(aVersion: TVersion): String;
...