Tag Info

Hot answers tagged

113

No, this is not bad practice. Relying on short-circuiting of conditionals is a widely accepted, useful technique--as long as you are using a language that guarantees this behavior (which includes the vast majority of modern languages). Your code example is quite clear and, indeed, that is often the best way to write it. Alternatives (such as nested if ...


43

I do not think it's good that they make a contest out of finding the most bugs. While it is true that their job is to find bugs, their job is not "find the most bugs". Their goal isn't to find the most, their goal is to help improve the quality of the software. Rewarding them for finding more bugs is about the same as rewarding a programmer for writing the ...


20

Let's say you were using a C-style langugage with no && and needed to do the equivalent code as in your question. Your code would be: if(smartphone != null) { if(smartphone.GetSignal() > 50) { // Do stuff } } This pattern would turn up a lot. Now imagine version 2.0 of our hypothetical language introduces &&. Think how cool ...


10

I am going to disagree a bit with the other answers. "Finding bugs" for a tester is a bit like "writing code" is for a developer. The raw amount is meaningless. The job of the tester is to find as many of the bugs that exist that they can, not to find the most bugs. If tester A finds 5 of the 10 bugs in a high quality component and tester B finds 58 of ...


7

You can take this further, and in some languages it's the idiomatic way to do things: you can use short circuit evualuation outside of conditional statements too, and they become a form of conditional statement themselves. E.g. in Perl, it is idiomatic for functions to return something falsy on failure (and something truthy on success), and something like ...


6

Based on my personal experiences, this is not a good thing. It almost always leads to developers filing bugs that are duplicates, ridiculous, or completely invalid. You'll typically see a lot of these appearing suddenly at the end of a month/quarter as testers rush to meet quotas. About the only thing worse than this is when you also penalize developers ...


5

It's not a particularly bad habit to have to want to get output when debugging (the worse habit is to not debug). Its just that we programmers are just so gosh darn lazy. Want output? Look there... System.err.println("Got an error: " + e); That's really easy. You don't need to worry about what logging framework you have, nor what log level it should be ...


4

Contractors from various fields typically bring their entire toolbox to a job. Sometimes, they even bring tools that they're not entirely familiar with, on the off chance that they might find them necessary... But also, probably because those tools came in a set, and that set was made in a 'one-size-fits-all' fashion, as it seems has been done here. You may ...


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.


4

Don't just use the default streams directly. Do you have any simple way of preventing this from happening when you don't actually want to debug your application? Is there any way for you to change the log output target without going over each line and changing it? Are all of the messages you're logging that way actually very serious and require immediate ...


3

God object is one of the worst "designs" you can create. Please, put some effort into separating different concerns. Your future self will thank you.


3

There are plenty of situations where I want to check one condition first, and only want to check a second condition if the first condition succeeded. Sometimes purely for efficiency (because there is no point checking the second condition if the first already failed), sometimes because otherwise my program would crash (your check for NULL first), sometimes ...


3

While I generally agree with dan1111's answer, there is one particularly important case it does not cover: the case where smartphone is used concurrently. In that scenario, this sort of pattern is a well known source of hard to find bugs. The problem is that short circuit evaluation is not atomic. Your thread can check that smartphone is null, another ...


3

Finding bugs is their job. As long as they aren't making things less efficient (for instance, by opening a bug for ech of 10 typos instead of one to cover several of them) this is encouraging them to do exactly what they're supposed to be doing, so I can't see much of a downside.


2

To get the 4 bits (1001) from your example 11001111 (= 0xCF), you need to shift it to the right by 3 and then do a bitwise AND with 00001111b, like so: (x >> 3) & 0x0F. The shift causes the 4 bits you want to be in the least significant position (0000000011001111 >> 3 = 00000000000011001), but then you still have to get rid of the most ...


2

doing unnecessary runtime tasks only to not mess up the code doesn't make sense to me Actually, messing up the code just because to avoid some runtime tasks for which the running time does not matter does make much less sense to me. Your priorities should be make it right make it clean make it fast enough exactly in that order. See also: Is ...


2

One consideration, not mentioned in other answers: sometimes having these checks can hint at a possible refactoring to the Null Object design pattern. For example: if (currentUser && currentUser.isAdministrator()) doSomething(); Could be simplified to just be: if (currentUser.isAdministrator()) doSomething (); If currentUser is defaulted ...


2

I'd go with the second approach, with a change which releases the handle when done. If each method takes care of getting, operating and releasing its own handle, then your application should be better suited to scale up (assuming you have some sort of pooling underneath). With the first approach, it is hard to say what will happen should two different ...


2

Coding standards are there to make it easy to visually parse the code. They are often different for each language, and rightly so. If someone else is going to read this code, then keep to the Wordpress conventions when programming for Wordpress. If you are the only person who will read the code, then do what makes it easiest for you. Personally, I wouldn't ...


1

There is nothing wrong with making a game out of finding bugs. You have found a way to motivate people. This is good. It's also revealed a failure to communicate priorities. Ending the contest would be a waste. You need to correct the priorities. Few real games have a simple scoring system. Why should the bug hunt? Rather than score the game simply ...


1

I think how it will be(or how it already is) if it goes on like this, you wont necessarily get lower quality. Al though I think it will decrease the quantity to quality ratio. It depends if this is a bad thing or not. It depends if reporting bugs about screen enhancements, usability, or stupid bugs. is something you really dont want. If this is clear ...


1

Anaconda minimal install is about 30MB, while full install is about 300MB. so your customized libraries can range in that interval. The main question is if servers disk space is so critical that 200MB make big difference. In that case, you can always do a script to install 'minimal version' and your choosen libraries. If you are thinking on deploy on ...


1

As it looks like these are primarily a list of exclusion filters, something like this might get you where you want to be (example in Java, includes calls to functions that probably don't exist as parts of the test): private static List<Predicate<Node>> AD_FILTERS = Arrays.asList( (node) -> node.getPreviousSibling().isIFrame(), (node) ...


1

Your absolutely correct with your thinking, yes you absolutely need to keep them separate. However, it doesn't need to be as hard as you might think it is, in order to get your layout working correctly across multiple devices. Realistically, you have 3 approaches that are considered modern practice in this arena. 1) Create a satellite site for each ...


1

I don't think logging is helpful. I think it's a waste of time, since what actually matters, uncaught exceptions, is already printed. From your quote about System.err: By convention, this output stream is used to display error messages or other information that should come to the immediate attention of a user even if the principal output stream, the ...



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