Tag Info

Hot answers tagged

33

In this instance, you could refactor the code into a separate routine, and then just return from the inner loop. That would negate the need to break out of the outer loop: bool isBroken() { for (i = 0; i < 10; i++) for (j = 10; j > 0; j--) if (j == i) return true; return false; }


33

The apparent need for a go-to statement arises from you choosing poor conditional expressions for the loops. You state that you wanted the outer loop to continue as long i < 10 and the innermost one to continue as long as j > 0. But in reality that's not what you wanted, you simply didn't tell the loops the real condition you wanted them to evaluate, ...


7

We write code for other humans to read. New technologies are intended to make code easier to read, not harder. There are good and bad ways to use new technologies. If you're trying to write "impressive" code, you're doing it wrong. I suspect it's not just the use of the technologies that is concerning people. If the way you're using LINQ made a huge ...


6

Three things come into my mind. First: 'simple' is not 'stupid'. Simplicity is the predecessor of elegance. Second: in your job, the most important thing to do is to be is a team player. Your boss is a team player. Is job is to keep the team together, and that means making your code understandable to your team mates and by that making you a part of the ...


6

Use a linter or some program or tool that automatically enforces style. That should alleviate the objections about it taking too much time. Most of the objections have to do with "I'm uncomfortable with that style." It doesn't matter. Coding conventions are all about uniformity. Enforcing that uniformity will make code reviews easier by eliminating ...


6

No, I don't think a goto is necessary. If you write it like this: bool broken = false; saved_i = 0; for (i = 0; i < 10 && !broken; i++) { broken = false; for (j = 10; j > 0 && !broken; j--) { if (j == i) { broken = true; saved_i = i; } } } Having &&!broken on ...


6

The conventions I use are //non-private variable variableName //private variable _variableName //methods MethodName //parameters parameterName //Properties PropertyName These are standard MS c# conventions. There is a list here. If you want something to help you keep nice clean code following conventions, consider Resharper add-on for Visual Studio


4

This is a difficult situation. First, do not get into a negative relationship with your boss, or with your co-workers. Above all, be positive, recognizing their valuable traits, and being helpful. Then, see what you can do to expose your co-workers to newer techniques. If necessary, include explanations in your code, so people can follow you. Appeal to ...


3

The question can be divided into "Why does Java C support brackets behind variables and even behind method signatures?" and "Why would Java inherit so much from C?"; Java also inherited other weird syntax, especially that for switch (why not use curly braces as for everything else and use : and break ?). To answer the first question - I believe back in the ...


3

The short answer is "it depends". I advocate to choose regarding legibility and understandability of your code. The goto way might be more legible than tweaking the condition, or vice versa. You might also take into account least surprise principle, guideline used in the shop/project and consistency of the code base. For instance, goto to leave switch or ...


2

In your case, goto is enough of an improvement that it looks tempting, but it's not so much of an improvement that it's worth breaking the rule against using them in your code base. Think of your future reviewer: s/he will have to think, "Is this person a bad coder or is this in fact a case where the goto was worth it? Let me take 5 minutes to decide this ...


2

As an alternative to promises you should have a look at the yield keyword in combination with generator functions which will be introduced in EcmaScript 6. Both are available today in Node.js 0.11.x builds, but require that you additionally specify the --harmony flag when running Node.js: $ node --harmony app.js Using those constructs and a library such ...


2

There are two options that one has for dealing with specific, frequently occurring immutable objects. You can either instantiate them each time, or you can use a constant that is probably stuck in a final static in some class. BigInteger for example has ZERO, ONE, and TEN. However, this is an attempt to avoid instantation of new objects. Say you're ...


1

It seems to me that you were given legitimate feedback from your manager. Not taking anything from it would be a lost opportunity for you. Whether or not your way is right or not your colleagues are struggling. If they're struggling the company will struggle and you will struggle providing tons of support when they're trying to debug, extend or otherwise ...



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