18

Is this a valid use case of Enums? In my opinion, using Python's enum module for this kind of task is highly idiomatic — I think you've chosen the best way to express your code's intent here. However, I think there are nonetheless several aspects I might do differently. Use more descriptive names for your attributes. The structure of your data is clear: ...


8

It's an excellent exercise to try to write your own library. Since you mentioned pandas and currency units, you might want to try pint. Pint is a Python package to define, operate and manipulate physical quantities: the product of a numerical value and a unit of measurement. It allows arithmetic operations between them and conversions from and to different ...


3

One comment about the design: your current list of units H = ("h", "duration") MW = ("MW", "power") MWH = ("MWh", "energy") EUR = ("Eur", "revenue") EURMWH = ("Eur/MWh", "price") DEGC = ("degC", "temperature") does not separate unit from ...


2

Bitwise Operators While your use of bitwise operators works fine as far as I can tell, I wouldn't expect them to be used like this in Python. So instead of if ((a == "boo") & ((c == 2) | (b == 3))): I'd prefer if a == "boo" and (c == 2 or b == 3): Also note that you don't need as many parantheses. processed = True if boo(a, c): ...


2

If your goal is to have good code, most of this shouldn't exist and you should make better use of built-ins, but it seems like that isn't your goal. If your goal is to demonstrate that you know how to write functions equivalent to the built-ins, you haven't quite hit your mark, because the built-ins are able to deal with negative numbers and your functions ...


2

The IEnumerator<T>.Current property must have only a getter. I.e., you are not allowed to change the Current value from outside. Only MoveNext() and Reset() are allowed. public TData Current => _current.Data; The IEnumerator.Current property can slightly be simplified. Add the expression body to the property instead of the getter (this defines the ...


1

There’s no point to doing a design review, since you’re reimplementing something—there’s no real designing being done. So I’ll just go straight to the code review. Code review It’s good that you wrote some tests to confirm your unique pointer is working. However, because you’ve jammed the actual code and the tests together, you’ve basically ruined the code. ...


1

Your move assignment leaks memory: Unique_Ptr<int> foo(); ... Unique_Ptr<int> p{new int{2}}; p = foo(); // <- leaks the original int I recommend you to add a swap(Unique_Ptr & other) and use that in your move assignment operator. That way, the Unique_Ptr&&'s destructor will take care of freeing the original ...


1

First of all, you don't need to write inline when a function is defined inside the class. You might notice that you've used it in some but not all of them; it doesn't add anything to the meaning. In particular, don't try to implement an assignment [operator] or a copy constructor (N.B. did you leave out the word operator when you typed the quotation?) ...


1

I'd write increment = (<|> (Just 1)) . fmap (+1) You can probably also write reverseBySecond = flip $ comparing snd if you don't mind getting EQ for equal pairs.


1

What are some of the pitfalls of defining these operators explicitly? What could go wrong? The best code you can write is no code. Every single line of code—every statement, every expression, every single character—introduces potential bugs, and needs to be inspected, tested, or both. The only possible way to have no potential for bugs is to not write any ...


1

My opinion is that you should test better, before asking for code review. line = " #Wartosc jest dodawana do listy pod hashowanym indeksem" for word in line.split(): content.append(word) for c in content: L[c] = c print(L["jest"]) Put a print statement inside each of your functions, for example print('__getitem__ ran'). Then keep ...


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