Do Hacklang Collections have higher order functions such as Reduce, Some, All or an easy way to implement such methods. The Collection I am most focused on is the Vector. It seems to only have Map and Filter. The others would help in writing more clean looking functional code.
Full information on the different Hack collections is best seen on the API docs for Vector (and other classes).
I also only see ->map and ->filter, though writing a utility function to do reduce yourself isn't particularly difficult, of course.
Related
My React application implements two business cases. They are similar in many ways, but differs in, for example, executable methods during the process:
Case A: doHardWork()
Case B: doSimpleWork()
The results of this methods are processed equally and previous methods can be the same too.
Every time than I need to use one of these methods I am forced to use switch/case construction to define what method I will use exactly.
For solving this situation I want to use something like polymorphism, but don't see that it is possible, because methods doHardWork and doSimpleWork refer on MOBX store variables and another methods. So I can't incapsulate the logic of specific business case to the specific class.
Please help to avoid switch/case. The project become overweighted because of it and hard to expand.
I've seen both of the following methods to use a filter in a controller/service:
$filter('myFilter')('myStuffToFilter', myFilterArgument)
myFilterFilter('myStuffToFilter', myFilterArgument)
They work equally well. Which method constitutes best practice?
While this is not a ground-breaking issue, I believe there is a difference and it's worth sharing (as did pkozlowski.opensource in his answer to a related question). Option 2 is better for the following reasons:
Cleaner syntax: It's a little cleaner, more straight forward and avoids the sequential parentheses syntax which is less common.
Provided solution: The myFilterFilter object is not available for code injection by accident. The AngularJS creates these <filtername>Filter objects for all filters (pre-defined and custom) and makes them available to the injector.
Documented solution: The AngularJS documentation recommends this solution in their documentation here.
I'm considering extending the MultiMap methods in Dapper to support more than 5 types. Was just curious as to whether there was a technical/performance reason for 5 or was it just an arbitrary number?
It was fairly arbitrary, and due in part to some implementation particulars that make it pretty awkward to extend arbitrarily - in particular because it uses generics. Changing to an implementation that doesn't use generics would allow a more type-array based approach, but then the lambdas etc (to stitch the data back together) become pretty ugly. There are, IIRC, some pending things in the pull request queue relating to this, but I have not had much available time to review them as of yet.
Also: arguably, if you're doing a query that involves that many types, you're probably already doing something pretty complex; it is hard to expose a friendly API for arbitrarily complex systems.
Just wanted to make you aware that more types have already been supported. (Just helping you NOT reinvent the wheel)
https://code.google.com/p/dapper-dot-net/issues/detail?id=50
At the bottom of the page you can get a git-hub change.
Matt
I have a hierarchy of stuff I want to display (at the same time) in both outline view and a custom view. Sort of analagous to the Buck and Yacktman (Cocoa Design Patterns) example in CH. 29, but with Outline instead of Table. I'll most likely have a detail view available also.
I've only used NSTreeController with a single outline view before. Now I have found that "arrangedObjects" aren't what one would like them to be. Also found that (for some reason) all the 'canInsert' and it's relatives have value NO (for some reason I can't find (or find with google)). So so far, it appears that NSTreeController is little help in coordinating my two views. (By the way, I've always had my add, delete functions work directly on the model in the past.)
it seems to me now it would be better and simpler to go back to using a data source approach, and use an architecture more like Buck and Yacktman's figure 29.4 (page 357) with a handmade mediating controller.
This has been hanging around for quite a while with no takers.
Just to close this out:
I've tried both NSTreeController and data source versions. Currently, I'm sticking with data source, since it seems to give me more flexibility.
-- The program I'm working on has been very much experimental, trying a number of different things. A secondary goal is to make an application I will find useful, and ternaryily :-) maybe make a cleaned up version for distribution.
What are the pros and cons of having multiple inheritance?
And why don't we have multiple inheritance in C#?
UPDATE
Ok so it is currently avoided because of the issue with clashes resolving which parent method is being called etc. Surely this is a problem for the programmer to resolve. Or maybe this could be resolve simularly as SQL where there is a conflict more information is required i.e. ID might need to become Sales.ID to resolve a conflict in the query.
Here is a good discussion on the pitfalls of multiple inheritance:
Why should I avoid multiple inheritance in C++?
Here is a discussion from the C# team on why they decided not to allow multiple inheritance:
http://blogs.msdn.com/csharpfaq/archive/2004/03/07/85562.aspx
http://dotnetjunkies.com/WebLog/unknownreference/archive/2003/09/04/1401.aspx
It's just another tool in the toolbox. Sometimes, it is exactly the right tool. If it is, having to find a workaround because the language actually prohibits it is a pain and leads to good opportunities to screw it up.
Pros and cons can only be found for a concrete case. I guess that it's quite rare to actually fit a problem, but who are the language designers to decide how I am to tackle a specific problem?
I will give a pro here based on a C++ report-writer I've been converting to REALbasic (which has interfaces but only single-inheritance).
Multiple inheritance makes it easier to compose classes from small mixin base classes that implement functionality and have properties to remember state. When done right, you can get a lot of reuse of small code without having to copy-and-paste similar code to implement interfaces.
Fortunately, REALbasic has extends methods which are like the extension methods recently added to C# in C# 3.0. These help a bit with the problem, especially as they can be applied to arrays. I still ended up with some class hierarchies being deeper as a result of folding in what were previously multiply-inherited classes.
The main con is that if two classes have a method with the same name, the new subclass doesn't know which one to call.
In C# you can do a form of multiple inheritance by including instances of each parent object within the child.
class MyClass
{
private class1 : Class1;
private class2: Class2;
public MyClass
{
class1 = new Class1;
class2 = new Class2;
}
// Then, expose whatever functionality you need to from there.
}
When you inherit from something you are asserting that your class is of that (base) type in every way except that you may implement something slightly differently or add something to it, its actually extremely rare that your class is 2 things at once. Usually it just has behavour common to 2 or more things, and a better way to describe that generally is to have your class implement multiple interfaces. (or possibly encapsulation, depending on your circumstances)
It's one of those help-me-to-not-shoot-myself-in-the-foot quirks, much like in Java.
Although it is nice to extend fields and methods from multiple sources (imagine a Modern Mobile Phone, which inherits from MP3 Players, Cameras, Sat-Navs, and the humble Old School Mobile Phone), clashes cannot be resolved by the compiler alone.