- There are many many languages without classes that make good use of enums
- Doing this refactoring is excessively verbose
- Someone making bold claims like this about a language feature that's never been considered error prone and been around since the beginning ought to provide some really good evidence to back things up.
There's cases where enums are good, and there's cases where polymorphic classes are good. Dismissing one of them by default is wrong, since both are useful at different times.
edit: and the citation there to Martin Fowler et al., Refactoring: Improving the Design of Existing Code doesn't even match the claim being made. That book mentions
- "The first part of this problem is that switch statement. It is a bad idea to do a switch based on an attribute of another object. If you must use a switch statement, it should be on your own data, not on someone else's." -- sure, I agree
- "Often you find the same switch statement scattered about a program in different places. If you add a new clause to the switch, you have to find all these switch, statements and change them. The object-oriented notion of polymorphism gives you an elegant way to deal with this problem." -- fair enough
This is a long way from "enums are a code smell," and honestly feels like padding the citation count. Another thing to note is that the second edition of Refactoring: Improving the Design of Existing Code says:
> Even in our more wild-eyed youth, we were never unconditionally opposed to the conditional. Indeed, the first edition of this book had a smell entitled “switch statements.” The smell was there because in the late 90’s we found polymorphism sadly underappreciated, and saw benefit in getting people to switch over.
> These days there is more polymorphism about, and it isn’t the simple red flag that it often was fifteen years ago.
In Swift specifically, switch statements are exhaustive, so adding a new case to an enumeration that is switched on will automatically give you compilation errors at every point in the code base where that enum is matched against.
Which, in my experience is a huge advantage rather than the supposed disadvantage Fowler is saying it is (although I could see that being the case in many other languages).
>This is a long way from "enums are a code smell,"
originally the meaning of code smell was not that code that had the smell was bad, but there was a chance it was and should be examined. For this reason of course it is useful to get rid of code smells so that people don't feel the need to investigate hey is this smelly code actually bad code.
But all that said not sure if an enum is a code smell.
on edit: this at any rate was the rationale behind the phrase code smell I was first introduced to.
> - "Often you find the same switch statement scattered about a program in different places. If you add a new clause to the switch, you have to find all these switch, statements and change them. The object-oriented notion of polymorphism gives you an elegant way to deal with this problem." -- fair enough
Even that seems like it could easily be way overkill e.g. if you have multiple switches which, say, generate a label from an enum, the first step is probably to add a utility function / method, not to migrate the whole thing over to polymorphism.
Although there is one thing to be said about context:
* OP works in C#, whose enums are literally useless (they’re like C’s)
* apparently even in Java (which at least has type-safe enums even if not sum types), `switch` is unable to check for completeness
Generally the issue with the switches scattered about (or more generally, and concern about conditions scattered about the codebase) is that the body of each case is different. Of course if all the bodies are the same the easier option is a utility method.
Switch statements are not required to be exhaustive, but switch expressions are. I’d have to check but I think it was found that changing the exhaustiveness requirement would break too much source code. The compiler will still insert some some sort of default case because somebody might add to the enumerator, and it might be in a separate compilation unit.
A C# enum is, like a C enum (as they were explicitly introduced to be compatible with those), just a bunch of constants for integers.
So when you have an enum-typed value, odds are good that it’s one of the named ones but there’s no mechanism anywhere preventing it to be any other integer of the underlying type.
> But how is that an issue? I guess when you are casting random integer to the enum-type without any checks?
Any caller can send any garbage (if you're publishing a package / API), likewise a dependency can return any garbage, etc... C#'s enums are entirely indicative.
I don't have a deposit banking relationship with any brick-and-mortar banks, so for me it's very convenient: I have a way to turn my paper money into electronic money.
That'd actually be acceptable to me, since I wouldn't feel the need for redundancy--but it looks like the cheapest 1TB SSD that can be found is $67, while I can get HDDs for $15.88/TB. That's x4.2 the price of an HDD, definitely not practical for me.
> Data leaving their network is going to be more expensive for them.
Not $10/50GiB more expensive. They want people using their streaming services, and I'm certain they already have their call center employees using the "tired of extra fees? just buy xfinity TV"
It's anticompetitive, other streaming services just can't compete on these terms.
That's very different--that's on my own hardware, and my fingerprints don't leave the phone. This is amazon's hardware, and they store the fingerprints in a centralized database.
What would be the proper way to do something like this? I've made a couple desks myself, but I've never been able to figure out a good way to do joints.
Dovetail and pin it all old style. A good rule of thumb is to not rely on friction for primary load bearing (e.g. nails in tension are bad but nails in shear or a peg being held in by friction are fine).
That said, a plywood deck that is glued and screwed down like a subfloor pretty much absolves all sins.
Dovetails are easy if you have the right tools. But that's a $100 minimum investment, so you're going to want to have multiple projects in the works to really make the investment worth it. Doing them by hand is completely possible, it just takes a lot of time and practice to get right. Mortise and tendon or lap joints are much easier to do with hand tools and are a staple of classic wood working. Plus they are really forgiving. Took off too little: grab some sand paper; take off too much: add more glue and sawdust.
For most projects, glue & screw is fine. It's cheap and low effort. I use it in every utility project because speed > looks. I've never tested it, but I'm pretty sure that connection would be stronger than the wood itself.
I've generally had two choices: 5-12Mbps DSL or cable. A couple times I was able to get Google Fiber, but I'm sure you know how limited the availability of that is.
You need to take 10 minutes out of your day to remove the plastic enclosure. Depending on your setup, you may also need to make some minor modifications to the drive: google.com/search?q=3.3V+wd+easystore
The theory is that this is a form of market segmentation, where enthusiasts/companies are willing to pay more for a bare drive regular consumers.
- There are many many languages without classes that make good use of enums
- Doing this refactoring is excessively verbose
- Someone making bold claims like this about a language feature that's never been considered error prone and been around since the beginning ought to provide some really good evidence to back things up.
There's cases where enums are good, and there's cases where polymorphic classes are good. Dismissing one of them by default is wrong, since both are useful at different times.
edit: and the citation there to Martin Fowler et al., Refactoring: Improving the Design of Existing Code doesn't even match the claim being made. That book mentions
- "The first part of this problem is that switch statement. It is a bad idea to do a switch based on an attribute of another object. If you must use a switch statement, it should be on your own data, not on someone else's." -- sure, I agree
- "Often you find the same switch statement scattered about a program in different places. If you add a new clause to the switch, you have to find all these switch, statements and change them. The object-oriented notion of polymorphism gives you an elegant way to deal with this problem." -- fair enough
This is a long way from "enums are a code smell," and honestly feels like padding the citation count. Another thing to note is that the second edition of Refactoring: Improving the Design of Existing Code says:
> Even in our more wild-eyed youth, we were never unconditionally opposed to the conditional. Indeed, the first edition of this book had a smell entitled “switch statements.” The smell was there because in the late 90’s we found polymorphism sadly underappreciated, and saw benefit in getting people to switch over.
> These days there is more polymorphism about, and it isn’t the simple red flag that it often was fifteen years ago.