Tag Info

New answers tagged

0

Microsoft has written and published a very good set of Cmdlet Development Guidelines Excerpt: The topics in this section provide development guidelines that you can use to produce well-formed cmdlets. By leveraging the common functionality provided by the Windows PowerShell runtime and by following these guidelines, you can develop robust cmdlets with ...


6

This pretty much always happens. If you were coding something you'd already done before, then why aren't you using that code? This is in part why refactoring (and iterative development in general) have become popular. People accept the fact that your first two tries will suck. Prototyping helps. Refactoring helps. Knowing that perfect is the enemy of good ...


2

The pat answer is to "follow best practices." A better answer is to "understand what you are doing, learn from your mistakes and get better." Today's best practices are tomorrow's cargo cults. How you get better works the same way in programming as it does in anything else: Know your fundamentals. Know your core programming language inside-out. ...


1

It depends on what language you're working with. Let's look at the informal definition of the Liskov Substitution Principle (herafter LSP): You should be able to use an instance of a subtype anywhere you could use the base type. That only tangentially impacts constructors. LSP doesn't particularly care how instances are created, only that once ...


2

Some languages (Scala compiled to JVM, Haskell, Ocaml, etc...) have pattern matching which is superior to switch since its deconstruct data structures and bind variables (locally to the matching case). For example, in Ocaml you might define a simplistic AST data type (a sum type or tagged union) for expressions as: type expr = Num of int | Sum of ...


4

No, switch statements are not generally used wrong. They are mostly used for their intended use: enumerating action alternatives for a smallish set of possible input values. It's more readable then a long if/else chain, compilers can emit very efficient code if the checked values are reasonably contiguous, and it's easier to write error-checking compilers ...


9

Since if/else is similar to a switch and often interchangeable, your confusion is understandable. Some languages, such as Python, don't even have a switch statement. Not surprisingly, when you Google for "python switch", the first result points to an alternative—a map. Not an if/else, but a map. While you can use if/else every time instead of a switch, you ...


2

I see what you're saying, but this is ultimately not improper. If it's just one or two elses, an if-else change will suffice. But if it grows to be more than that, I'd say switch statements can quickly turn into something that's just cleaner and less of an eyesore to look at. Or...depending on who you are personally, it could turn it into something that's ...


-2

I personally find camelcase to be more natural when coding variables, but because variables in PHP are case sensitive, and it's no fun hunting through code looking for a variable you forgot to make camelcase, I always use snake case for variables. While its true that the conventions are mutable, coding after someone that has used camelcase on variables, ...


3

Stick to the naming conventions specific to the platform you're using. It's easy enough for any developer with an IDE to see if a method or class comes from the SDK, a third party library or your own code. It's usually as easy as mousing over the code and seeing a qualified name. Besides, I don't think it's really that important for a developer to tell the ...


3

Unless you have any compelling reason, it is usually recommended to stick to the code conventions of the programming language you are using. Changing method naming conventions could make developers think that they might be consuming some external service or maybe crossing some other boundaries. If you would like to point out that the method is not available ...



Top 50 recent answers are included