Skip to main content
The 2024 Developer Survey results are live! See the results
31 votes
Accepted

A Failable<T> that allows safe returning of exceptions

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 ...
Eric Lippert's user avatar
  • 14.9k
15 votes
Accepted

'StrictInt' Python object class that prohibits casting numbers with non-integer components to `int`

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. ...
Gareth Rees's user avatar
  • 49.6k
11 votes
Accepted

Enforcing string validity with the C# type system

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. ...
t3chb0t's user avatar
  • 44.3k
9 votes

List<T> implementation for VB6/VBA

Your implementation of Sort would be optimised by implementing IndexOfMin so that ...
Mark Hurd's user avatar
  • 326
9 votes
Accepted

Validating a list of dictionaries of names and tags

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 ...
Grajdeanu Alex's user avatar
8 votes

A Failable<T> that allows safe returning of exceptions

A few minor things: You do not check for null in GetHashCode() and in equality operators. You probably should, since both ...
Nikita B's user avatar
  • 13k
7 votes
Accepted

C++ identity function

Well, that looks like a straightforward use of perfect forwarding in the parameter (T&&, std::forward<T>) and in ...
Quuxplusone's user avatar
  • 19.4k
7 votes

A Failable<T> that allows safe returning of exceptions

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 ...
Mr.Mindor's user avatar
  • 346
7 votes
Accepted

A type for prime numbers

Unfortunately, it's not safe. That's due to the records. If I know any Prime, I can construct a new Prime: ...
Zeta's user avatar
  • 19.3k
7 votes

Binary to decimal (and back) converter in c++

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 ...
pacmaninbw's user avatar
  • 24k
7 votes
Accepted

Address class in PHP 7.4 with types

I saw your post yesterday before it was deleted. I didn’t have much to suggest but after seeing this code there are a few things I would change. The suggestions by YourCommonSense are great: Specific ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
6 votes
Accepted

Area under curve

solve's type is a disaster. I guess its provided by HackerRank, so that's not a surprise and not your fault. This is also the reason why you get so many type errors....
Zeta's user avatar
  • 19.3k
5 votes

'StrictInt' Python object class that prohibits casting numbers with non-integer components to `int`

naming I try to avoid 1-letter variable names, unless it are x, y, z for coordinates, or i during an iteration, so I would ...
Maarten Fabré's user avatar
5 votes

Python simple type checking decorator

To amplify @200_success’s comment: Python 3.5 introduces type hints. Eg) ...
AJNeufeld's user avatar
  • 33.9k
5 votes

Address class in PHP 7.4 with types

I was able to come up with two suggestions so far Using a generic exception is definitely not the way to go. Ask yourself a question, what your code is supposed to do when such an exception is thrown? ...
Your Common Sense's user avatar
4 votes

Improving General Algebraic DataType type-safe code for AA trees

As suggested, I'm doing a review myself after a few years. First, let's use GHC's extensions to derive the phantom types from data definitions. This also has the advantage of having proper kinds for ...
Petr's user avatar
  • 3,070
4 votes
Accepted

SI type safe unit calculations

Value issues friend bool operator==(const Value& lhs, const Value& rhs) can be ...
hoffmale's user avatar
  • 6,498
4 votes
Accepted

Nop class which can get optimized away

I would like to get the elephant out of the room first by saying that the code doesn't really solve the problems it wants to solve. My post will compare the code in the question with the following ...
Incomputable's user avatar
  • 9,504
4 votes
Accepted

Reusable storage for array of objects

Use the return value of placement-new In your code you write: T* tmp = reinterpret_cast<T*>(paligned); However, at this ...
G. Sliepen's user avatar
  • 58.8k
4 votes
Accepted

Type-safe number serialization-deserialization

Reduce responsibilities Your AppendNumber() family of functions do too much; they not only take care of serialization, but also deal with conversions and offsets ...
G. Sliepen's user avatar
  • 58.8k
4 votes

An Attempt at Creating a Type-Safe, Generic Swap Macro With Compile Time Error Checking

SWAP(a, b) looks wrong. The below code looks like the values of a, b are not changed as ...
chux - Reinstate Monica's user avatar
3 votes
Accepted

Type converter framework (v2)

Thanks for sharing – it is an interesting problem :) I would go with mutable state only when it is required for performance optimization. Immutability almost always makes code a way cleaner and ...
Dmitry Nogin's user avatar
  • 6,131
3 votes
Accepted

TextBoxes for various number types

class TextBoxNum Abbreviation should be avoided when naming a class: Num -> Numeric The ...
Xiaoy312's user avatar
  • 3,136
3 votes

C++ FlagSet: typesafe usage of enumeration as bitset/bitmask

Thanks, @Xaqq, this is really nice! I published the code in GitHub with amendments from @Barry and @lightness-races-in-orbit and minor modifications, usage is as follows: ...
mrts's user avatar
  • 159
3 votes

Safe, fully standards-following integer abs in C

This kind of code relies on careful reading of the standard, so if it were me I would add cross-references to the sections of the standard that I was relying on, for example I might write: ...
Gareth Rees's user avatar
  • 49.6k
3 votes

Formatted print without the need to specify type matching specifiers using _Generic

A self answer per: If you want to show everyone how you improved your code, but don't want to ask another question, then post an answer to your own question. @Mat identified undefined behavior of ...
chux - Reinstate Monica's user avatar
3 votes
Accepted

Convertible templated math vector

I had to adjust your code style a bit before I could easily read the code. In particular: Use InitialCaps for template parameters Add a space before ...
Quuxplusone's user avatar
  • 19.4k

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