9

Well your code is all broken. But we will get to that as we answer your questions: Answers to Questions How do you keep track of includes? Even in this short example I now have includes that are not needed anymore. Only include a header file if you need the class definition. Forward declare everything else Using this rule it is easy to only include ...


6

I am unfamiliar with both the design pattern and the backtracking algorithm, so almost all of my comments will be nitpicks. utils.py kk_sub: I prefer values[0] - values[1] in {value, -value}, which will work if value is negative. Maybe we know that it will always be nonnegative, though. kk_div: I prefer values[0] == values[1] * value or values[1] == values[...


6

First of all, IMHO the code is well written and has some meaningful comments. Visitor Pattern Actually, I am not sure if the OverflowingBucket has something to do with the visitor pattern. In my eyes, the visitor pattern can be used to add logic to a data structure by implementing visitors. A visitor visits each element of the data structure and decide ...


6

The Visitor Pattern The main purpose of the Visitor pattern is to define extra elements of functionality for a number of classes in a single place. Your PersonVisitor and AnimalVisitor don't really demonstrate this at all - the name indicates that each visitor corresponds to a target type, not a piece of functionality. Better would be a single ...


5

Warning! Arm Chair Quarterbacking in progress. Given that I offer this. Game Class Why is this Board.moveList in the Board class? You need a "driver" for a chess game and that would be a Game class. "A game consists of (has) moves" makes more sense. The Game gives us a conceptual framework for a richer chess game. A Game has players, may have a timer for ...


4

Is this higher order function any use at all without relying on a side-effect? The answer to this question is obviously no, since the function returns always nil. The general question I'm seeking to explore here is the purity or non-purity of higher order functions in practical use cases (and hence, how to use them well). I'm not sure to understand what ...


4

Visitor A visitor pattern would look more like this: class Visitor; class Asteroid { public: virtual ~Asteroid(); virtual void accept(Visitor&) = 0; // The asteroid accepts visitor }; class ExplodingAsteroid; class StonyAsteroid; class Visitor { public: // Limitation of the visitor that it must know about // ...


3

I have implemented something like that in one of my projects, the trick is to use CRTP to pass the Child type to the parent. This is a simplified code : #include "collisions.h" #define SHAPES Box, Sphere, Mesh class Box; class Sphere; class Mesh; class Geometry; // Collidable defines all the pure virtual functions. template <typename... Shapes> ...


3

The visitor pattern and open closed principle. There is a mild conflict here. The visitor pattern is very good when you have a static class hierarchy and just want different ways to traverse the nodes in some collection. In these situations the visitor pattern behaves very well. BUT If the class hierarchy is not stable and you are adding new types of ...


3

Review Firstly, is there a name for this variant of the visitor pattern? You have made what I like to call the inviting visitor pattern. I'm not sure this pattern is common, but I have seen it before, disguised and usually involves 3 (types of) classes instead of 2, each with their own concern. inviter: let reference invite visitor reference: let ...


2

General things: The visitor pattern is more suited for object-oriented languages. Whether Go is object-oriented is up for debate, but fact is that many OOP patterns are implemented differently in it (or don't make sense at all). Specifically, I don't see an advantage to XmlVisitor and JsonVisitor over xml.Marshal and json.Marshal. That said, design is ...


2

I don't have any strong objections to your code and the other answer does a good job of addressing some slight naming issues. My problem is on a much larger scale - I think your domain model is far too simplistic. Consider this CSS: .i-should-be-applied-first { position: relative; } #i-should-be-applied-second { position: static; } Now, look at ...


2

A quick review: You shouldn't name classes/methods after patterns (except when pattern name makes sense semantically, like factory). StyleVisitor.Visit does not tell me anything, about what this class does. But, say, CssManager.ApplyStyle does. Its hard to tell what Element method does at first glance. I mean it is called Element (add a verb?) but it ...


2

The design is overly complex. You gave some reasoning on your design decisions, nevertheless I want to raise some questions. Design The visitor pattern is intended to allow extension by implementing Visitors later on. This is very common for serializers, formatters and stuff like that. You could simply have an abstract reduce in your Cage. Another ...


2

... In order to do that, I have to make sure that my sequential BFS works perfectly. ... Have you tried writing some unit-tests to prove or disprove that the function? On the whole it looks alright to me though it really depends on what the visitor.visit(...) does. Also, not clear what outgoingNeighbors does. Minor comments : q.forEach(currNode ->...


2

I prefer simplicity when it comes to async/await. await is useful and makes the code cleaner when you have code that executes after a Task completes. Using it just to pass tasks along methods (like in public async Task Add(U item)), creates noise. In public async Task<bool> Visit() you only use await to wait for the task to finish so that you can ...


2

Only focusing on is and as class PersonVisitor : IVisitor { public void Visit(IElement element) { if (element is Person) { Creature creature = element as Person; Console.WriteLine("{0} is a good {1}", creature.Name, "Person"); } } } The is is basically doing the same as the as. It is doing a ...


2

At the moment it seems your board holds 64 (8*8) Pieces : private Piece[][] board; It would be more logical to have : private Square[][] board; Secondly, you can avoid a lot of nested loops by representing the board with a one dimensional array : private Square[] board; Which is simply putting all rows in one big sequence. For the clients of Board ...


1

the typical operations like mapcar or reduce - which return a value - could also be provided in similar fashion for trees. Note also that your function is not tail recursive and may cause a stack overflow...


1

All spaceships calls the same function: ShipCollidesWith(std::shared_ptr<CAsteroidBase>) the functions with more concrete Asteroid types are not called: void ShipCollidesWith(std::shared_ptr<CExplodingAsteroid> aExplodingAsteroid) const override; void ShipCollidesWith(std::shared_ptr<CStonyAsteroid> aStonyAsteroid) const override; So ...


1

No, this is not a visitor pattern. You are trying to do double dispatch. You are actually calling void ShipCollidesWith(std::shared_ptr<CAsteroidBase> aAsteroidBase) every time. There is nothing I see that will then do the second dispatch to the right derived class for the actual type of the parameter. What did your test program print?? There are ...


1

Inheritance I believe that inheritance based OOP is painful to use in C++ compared to languages like java. In my opinion, static polymorphism is better. Runtime polymorphism is hard to do because C++ has manual memory (and ownership semantics in general) and local variables are strongly typed. Use cases Personally I can't see a use case for visitor. They ...


1

You can improve naming. Names like IVisitor are good to illustrate the pattern, but in production code I would rather have a name that tells me the purpose of the interface, not which pattern it represents. For example, this looks a lot better, IMHO: internal abstract Element Transform(ITransformer transformer); It looks like you assume that BinaryElement....


Only top voted, non community-wiki answers of a minimum length are eligible