Tag Info

New answers tagged

1

I've had this exact situation come up with a co-worker and when reviewing code from contractors -- the code should always convey your intent and expectations as clearly as possible given the constraints of performance and size. Performance with SQL relies upon the query optimizer -- while it probably won't make any difference, if it does, more likely than ...


0

On the first sight I think it should stay in the Value Object because of cohesion and encapsulation principles - getChildMap() method implementation is intimately connected to the implementation of MyContainerVO object so it should stay inside this object without necessarily exposing the implementation details (childList). The problem here is that it's not ...


5

As far as I can see, when you write: I made some changes which affected the expected array element position The advantage that you're focusing on is that in Method #1, the start position is only found in one place (the initial value of i) whereas in Method #2, that information is implicitly contained in all four array indexes. Seen this way, the ...


2

I think its fairly clear that a consistent programming style can help some things especially if you are publishing your code. Prevents unusual style Limited code difference between versions on check in to source control Consistent style across large code base eases understanding However, I would say its definitely an expensive thing to have. You have ...


4

Does it really help to have a very specific rule set? No. Quite frankly, no. Or, to put it more constructively - take a look at any source code off github or sourceforge, can you read tit? If the answer is "yes" then you've just demonstrated that a single style is not important for readability. What does help readability is readable code, which may ...


5

Your first method has 4 side effects (the pre-increments) while the second has none. In general you should avoid side-effects if you can. Furthermore, the second one is more clear about your intent. If I would see the first one in someone else's code I would ask myself if there was any reason for performing the pre-increments. So, stick with the second ...


3

The First method is horrible on my vision and it does not prevent "Exception". The same feelings I have when I see "magic numbers"! XD If possible, you need to change the architecture, something is wrong! Or You need to check it before to use it in the method! Or be right that those params always come with their values filled and in the same order! Did You ...


4

Names should be expressive in direct proportion to their scope. A loop variable should have a really small scope, so it's perfectly alright to just call it s. If this makes the code unreadable, you should refactor the loop code into a method, not find a longer variable name.


2

Unfortunately, I don't think there is any way to achieve your goal. Your workplace has made Java the first-class language and culture, and made C# second-class. Trying to raise this issue will possibly make you an unfavorable person among the coworkers. That particular coding style may also have the backing of some senior staff in the company. Given that ...


4

I'd say if your Java devs regularly program in C# and vice versa, they might have some argument for making them look the same (slightly easier to read). But even then, differences can be useful enough to trump reading ease. I for one like to use same-line-open-brackets in JavaScript to remind my brain at all times that the code I'm looking at is not C#. ...


3

There is a case for different styles for each language - it helps you remember that you're writing something different, and thus will help to prevent some subtle errors due to language similarities (ie where you are still thinking Java techniques when writing C# code and vice-versa). It can slow you down a little when switching, but frankly - this is a ...


2

Yes, some times it is very convenient to be able to locally modify a pass-by-value argument to a function. For example, the argument might be a reference to a node of a linked list, and within the function you may want to traverse the list, so you will want to be doing node = *(node.next);. So, ill-advised? definitely not, in my opinion. There exist ...


7

Yes, so the function can change thing. In general, it is best to put the behavior on the object itself. In other words, prefer this: class Thing { public: void do_stuff() { ... } }; ...to this: void do_stuff( Thing & thing ) { ... } However, both examples are perfectly valid and usable. One good example of a non-member non-const ...


5

There are reasons why you might want to change things in place. One reason might be performance: it's expensive to make all those new objects for output. There are reasons why you might write things in a more functional, immutable style. One reason is referential transparency. Another is easier and more reliable concurrency and function composition. ...


0

Even though the question is quite old I thought of adding couple of points which I read from a book worth mentioning here. The run-time serialization engines persist the name of the filed in a serialized stream. The name of the backing field for an Automatically implemented property ( AIP )is determined by the compiler, and it could actually change the ...


0

If you use an editor in a GUI, then the 80 characters per line is irrelevant, since most decent editors - for example Notepad++ - have a button to toggle line wrap. With that, it should not be a problem, even when viewing the code in a thin window.


0

As one opinion from someone who does request code samples when evaluating candidates, there are a few high-level features (content of the code) and a few low-level features (structure of the code). High level features: Identity: The flavor of the code. If you're billing yourself as a UI/HCI coder, I want to see a good look/feel for something visual when I ...


7

Object.create is defined in newer versions of browsers (can't say exactly since when). You can see its description on the Mozilla developer network. This is just a polyfill (quite similar to the one on that page, with a few less checks) to be able to use the same function on older browsers. On newer browser it is already defined as a function and will thus ...


-1

The preferred coding style would be (b) according to all style guides that I've seen (e.g. https://github.com/objc-zen/objc-zen-book#property-declaration). They recommend explicitly specify readwrite attribute (for the sake of clarity, I guess).


0

One argument I'm missing here is the possibility of increased protection against cross site scripting attacks. It's possible to disable the execution of inline JavaScript in modern browser via the Content Security Policy. This reduced the risk of your site falling victim of XSS. This may be a more convincing argument to make to your management to invest in ...


0

One reason NOT to use InLine Javascript (not even onclick="DoThis(this)" on buttons), is if you intend to make your web application a Chrome App. So, if you are planning to port your web app into a Native Chrome App, start by NOT including ANY inline javascript. This is explained right at the beginning of what you will need to change (mandatorily) from your ...


0

A more fundamental question is whether to define the operator() (by the class) for this purpose or not. Alas, this decision has already been made by the author(s) of the matrix class, so we should consider its usage to be compatible with the intent of the author(s). Indeed, this is what most matrix (or multi-dimensional array) libraries would choose to ...


4

Use operator overloading if it improves code clarity and maintainability. Sometimes it helps clarity and maintainability: a + b is shorter and clearer than a.addTo(b), it makes it easier to write generic algorithms (e.g., templates) and change data types, etc. Sometimes it hurts clarity and maintainability: overloaded operators can be surprising ...



Top 50 recent answers are included