New answers tagged

0

NDepend can be used to enforce various coding standards on a .NET Code Base. It has around 200 default code rules that can be browsed here. Also it is easy to customize existing rules or create your own rules since with NDepend a rule is just a C# LINQ query. Disclaimer: I work for NDepend


2

As a general rule, attributes of a class should be part of the public interface if and only if it makes sense within the contract of that class that callers would have access to that attribute. If not all the values that can be assigned to the attribute are valid within the invariants that are supposed to hold for the class, then it might be better to not ...


1

I am uncertain when should one be more strict with these cases I would argue that one should be more strict when it's important to be more strict. In your example you end up with a divide by zero problem. Is that bad? If this is an internal tool and the cause of the error is obvious because its only used by developers, then it's probably fine the way it is....


2

Python has no good language-level encapsulation mechanisms, so in a way this doesn't matter. But Python linters do recognize the “leading underscores mean private” convention, so respecting this encapsulation can be enforced. Here, just adding an underscore will make the intention of the code much clearer. You shouldn't necessarily go and seek out any such ...


1

Depending on abstractions, creating single-responsibility classes, and writing unit tests are not exact sciences. It's perfectly normal to swing too far in one direction when learning, go to an extreme, and then find a norm that makes sense. It just sounds like your pendulum has swung too far, and might even be stuck. Here's where I suspect this is going ...


2

So that's a total of 15 classes (excluding POCOs and scaffolding) to perform a fairly straightforward save. That's crazy.... but these classes sound like something I'd write myself. So let's have a look at them. Let's ignore the interfaces and tests for now. BasePathProvider - IMHO any non-trivial project working with files needs it. So I'd assume, there's ...


11

Tasks that used to take 5-10 files can now take 70-100! This is a lie. The tasks never took only 5-10 files. You are not solving any tasks with less than 10 files. Why? Because you're using C#. C# is a high level language. You are using more than 10 files just to create hello world. Oh sure you don't notice them because you didn't write them. So you don't ...


4

I would like to expound on some of the things already mentioned here, but more from a perspective of where object boundaries are drawn. If you're following something akin to Domain-Driven Design, then your objects are probably going to represent aspects of your business. Customer and Order, for example, would be objects. Now, if I were to make a guess ...


28

Tasks that used to take 5-10 files can now take 70-100! This is the opposite of the single-responsibility principle (SRP). To get to that point, you must have divided up your functionality in a very fine-grained way, but that's not what the SRP is about -- doing that ignores the key idea of cohesiveness. According to the SRP, software should be divided ...


100

Now, to build a simple file saving application you have a class to check if the file already exists, a class to write the metadata, a class to abstract away DateTime.Now so you can inject times for unit testing, interfaces for every file containing logic, files to contain unit tests for each class out there, and one or more files to add everything to your DI ...


10

It sounds as though your code isn't very well decoupled and/or your task sizes are way too big. Code changes should be 5-10 files unless you're doing a codemod or large scale refactoring. If a single change touches a lot of files, it probably means that your changes cascade. Some improved abstractions (more single responsibility, interface segregation, ...


0

The origin of the 80 character limit was from an era where screens could only handle 80 characters, and that was only if you had something new enough. It lasted a little longer because early printers could only handle 80 characters with print that was legible and 1 inch borders. Now, our screens can handle well over 100 characters per line, and the only ...


4

Follow an arbitrary rule they said. It'll be fine they said. We have discovered the source of all perfection they said. There can never be anything that breaks the rules they said. They obviously never wrote code... Having a formatting guide is great, it helps people answer the same question with a predictable answer. But - and there is always a but - ...


0

I think it could not be good idea to replace multiplications with divisions because CPU's ALU (Arithmetic-Logic Unit) executes algorithms, though they are implemented in hardware. More sophisticated techniques are available in newer processors. Generally, processors strive to parallelize bit-pairs operations in order the minimize the clock cycles required. ...


1

Simple. Keep a notebook which records all work done that day and lessons learnt. Make a record every time you stop work. I use // to indicate breaks in work but do whatever suits you. This is also a valuable tool for project management queries when they're asking why you didn't finish X, Y & Z on a given day. For a more senior (i.e. older) developer ...


0

Do you follow AGILE ? If you do then you can have sprints, with Kunban charts... So it could point you out to the feature \ bug you were working on... How it going to help OP ? When user stories are broken down to tasks, ideally tasks should be less then a day, so when you come after 2,4,8 weeks holidays, you will work on next task assigned to you :) ...


3

Personally, I leave an intentional compile error. I write a short comment to myself in the code. Then I uncomment it. When I get back, by force of habit I start up my IDE, build, and...hey, something's broken! I go there, and there's my note, telling me what I was working on.


0

I sometimes use a counter-intuitive approach, especially over a weekend. Start on something and leave it slightly unfinished, may not compile, fail a unit test etc. When I come back, this jogs my memory sufficiently to continue working. P.S. This approach may not work for everyone. :)


7

The most obvious recommendation is to always stop at a point where all of the work is "done". So when you return, you start on something new instead of trying to remember where you left of. Instead of looking at it as a vacation time, look at it as if you worked in some different part of the application. So after few weeks, you return to module you worked ...


8

Copious notes. Write down your thoughts, your progress, in as much detail as needed to clear your mind. It's no different from when you do a problem analysis tracking down a bug and someone else is going to execute the fix (or yourself at some indeterminate point in the future). Write down EVERYTHING of consequence. When I do it I won't usually write in the ...


4

How do you know where you stopped in your codes after a 2-week break? The same way I know where I stopped after I take a bathroom break. Notes. You take notes, you make to do lists, you don't walk away from the 2 hours of work that it took to get an idea spun up in your brain without writing it down. Add method names, file names, ideas worth exploring, ...


Top 50 recent answers are included