31

First: congratulations, you have rediscovered the error monad. https://hackage.haskell.org/package/mtl-2.2.1/docs/Control-Monad-Error.html Second: as noted in the comments, C# already has the concept of "wrap up either a value or an exception, namely, Task<T>. You can use Task.FromException and Task.FromResult to construct them. Of course Result on ...


30

OK, went through the code and gave this a bit of thought over the past couple of days. As far as the implementation goes, I don't see a whole lot that I would change (that you didn't identify in the answer above) other than a couple nit-picky things. First, is the use of the this variable identifier. I couldn't find anything that justifies the naming and ...


23

Public Function ToString() As String 'Returns a string that represents the current List object. ToString = StringFormat("{0}<{1}>", TypeName(Me), _ Coalesce(this.ItemTypeName, "Variant")) End Function This means the string representation of this List is "List<Variant>" when this.ItemTypeName is empty ...


17

You should create a Dictionary<Type,Type> that would associate your object's type with their DTO equivalent, so you wouldn't need any if. Then you can use the dictionary to find the types to map. ex : //This should be instanciated wherever you want, but try to do it only once. //The dictionary should be static dictionary = new Dictionary<Type,...


16

This looks pretty good. I'd propose the following. First, you use set_value in exactly one place. It's a pretty unnecessary function, and just this would suffice: FlagSet &operator|=(const T &val) { bitset.set(static_cast<utype>(val)); return *this; } Second, for &=, the expression expr ? true : false is an antipattern that can ...


15

Converting everything via a float means that you get the wrong result whenever the input cannot be represented exactly as a double-precision floating-point number. For example, this is surely not acceptable: >>> StrictInt(10**23) 99999999999999991611392 There's an OverflowError when the input is too large to be represented as a float: >>>...


13

I don't think you should treat the units as disjoint entities between which you convert. You have started your post by saying Angle can be represented using following types But actually what you meant is "units". So the entity you are trying to measure is an angle. And code using it should, for most parts, not care what unit it represents - just that ...


11

A few notes: Your included libraries and definitions at the beginning of your code is not very organized. #include <avr/io.h> //#undef __FLASH #ifndef __FLASH #include <avr/pgmspace.h> #define FLASH(x) const x PROGMEM #define FLASH_P(x) const x * const PROGMEM #define FLASH_PR(x, y) (x *)pgm_read_word(&(y)) #else #define FLASH(x) const ...


11

I have recently earned my M.Sc. in Comp.Sci. and one of the things that was my main gripes with any examples given to use during programming classes was the lack of consistency. So I'll say this, please be consistent and if you implement one arithmetic or relational operator you need to implement all of them that make sense. And show them how to implement ...


11

One edge case you're missing is how to handle null. isEmpty(null) will fail because Object.getOwnPropertyNames(null) will throw TypeError: can't convert null to object. Also be aware that isEmpty(NaN) will return false, which may or may not be what you want.


11

C# events are type-safe. The common (and recommended) pattern is to use EventHandler<T>, where T is a custom type deriving from EventArgs, containing the data of the event. You should use this pattern if possible, especially if you're writing a library that will be used by third parties. The problems that I can see in this pattern are: The sender ...


11

Review I find this is a very nice idea that I have borrow from you and while doing this I'd change a couple things to make it more mature and even more flexible. : IComparable, IEnumerable, IEnumerable<char>, IComparable<string>, IComparable<ValidatedString>, IEquatable<string>, IEquatable<ValidatedString>, IXmlSerializable ...


10

I think the itself class might be mis-named, because it is really 'Empty-able' not Nullable or 'Nothing-able'. You have to keep in mind that Empty, Null, and Nothing are very different concepts in VB6. Setting and object to Nothing is basically just syntactic sugar for releasing the pointer to the Object. This is the same as asking for ObjPtr() to return ...


9

Your implementation of Sort would be optimised by implementing IndexOfMin so that Min = Item(IndexOfMin) (with a caveat for an empty List), but you can then use the O(1) RemoveAt instead of the O(n) Remove at the end of the Do Until loop. Similarly for IndexOfMax, Max and SortDescending, of course. I'd consider making IndexOfMin and IndexOfMax Public to ...


9

There're some modules that might help you get rid of the structure you're complaining about like marshmallow or voluptous and since you didn't added the reinventing-the wheel tag I guess that's perfectly okay. For the sake of example, I'll refer to the former one because IMO it better fits our purpose (and is also probably clearer). From the docs: ...


8

because it demonstrates type-safety w.r.t. preventing accidental swapping of parameters It does that: because the constructors which take an int parameter are marked explicit. has anyone comments about my demonstration code? I'm unsure why you mark member methods as friend. Perhaps the Date constructor should implicitly invoke Date::normalize (because ...


8

I'd consider a simpler, single class: class Angle { // The 'native' type, passed to System.Math methods public double Radians { get; set;} // Factory methods public static Angle FromRadians(double d) { ... } public static Angle FromDegrees(double d) { ... } public static Angle FromDegrees(int degrees, int minutes, double seconds) { .....


8

A few minor things: You do not check for null in GetHashCode() and in equality operators. You probably should, since both Exception and Result can be null by your design. You should re-use single equality implementation. For example, != should just return !(a == b). Otherwise this implementation looks alright to me. I would probably make T conversion ...


8

General Observations I'm mainly looking for error checking / type safety advice. There doesn't seem to be a lot of error checking on user input and user input is one of the places where error checking is most important. For instance, the code doesn't handle negative numbers but there is not checking for negative input. The code also doesn't check for lack ...


7

There's very little I would salvage from the model code. Converting the arguments list into comma-separated string is a little hackish and not very efficient (nevertheless it works, and I'd be totally OK with it for a quick throw away script). Therefore I would not use getListFromString. askUser is not needed since we're not interacting with the user. There'...


7

Adding to @Comintern's excellent answer, the private type doesn't need an IsNull member, since the class only accepts value types, the correct semantics for "null" values is vbEmpty. The Set accessor is therefore not only wrong, it's also ambiguous - not only in attempting to assign Nothing to a value type, but also because Value being the default member, ...


7

This code looks very clean, It looks like it handles edge cases well. I especially like the way that if it converts to the specified data type that it does it and doesn't make you convert explicitly. that is very slick! I would definitely like to see some code that puts it into play. Not much to review here, but very good code and good syntax. Edit I ...


7

Your implementation will be really hard to maintain as you keep adding different operations. Also the fact that you have multiple classes to represent single entity is kind of weird. For example, look at DateTime implementation. It represents time in various formats via exposed properties and formattable ToString and Parse methods. But when it comes to ...


7

This method really shouldn't be generic, switching on typeof is generally a clue here. While generics are nice and this does allow the caller to know what object they'll get back, this is essentially a method that takes object and switches, which is not good. Can you think of a solution that better uses Polymorphism? The easiest thing here would be to dump ...


7

I know this is technically outside the scope of the review here, but your first parameter's type is Method. This enum desperately needs to be renamed. When I see Method, I cannot help but think of a programming method... I think you're passing a pointer to a class's method here. This type needs a better, more descriptive name. Our sender parameter doesn'...


7

Another way to do this is to remove NULL values from the comparison to begin with, like so: return Context.TblNumbers .Where(m => m.Number != null) .Where(m => convertedNumbers.Contains(m.Number.Value)) .Select(m => m.Number.Value) .ToList(); I think this also reads more naturally since you ...


7

For the sake of a consistent and discoverable API you should have a non-generic version of Failable. For Consistency: If I'm presented with two methods that can fail to do their job, then I'd expect to check for the success/failure in the same way. I shouldn't check result.Passed some times and result == null at other times. For Discoverability Using ...


7

Unfortunately, it's not safe. That's due to the records. If I know any Prime, I can construct a new Prime: import Data.Numbers.Primes.Type example :: Prime -> Prime example p = p {getIndex = 0, getValue = 0} -- whoops So you want to get rid of the records in your type and write the getters by hand: data Prime int = Prime int Int getValue :: Prime int ...


6

What you are doing appears to be sane. The use of generics is primarily as a compile-time validator (and it makes some code simpler, like not having to cast things). If you don't know the types of your data at compile time, then you can't use generics. So, you have run-time specified data, and that's OK. Do you handle that as well as it can be handled? ...


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