Tag Info

New answers tagged

1

We had a highly escalated support case once about passwords being printed in the log file and as you can imagine, management jumped into fire-fighting mode, directing the devs to fix it 'by all means necessary.' I'm not sure which language you're using, but here are the several measures that can be taken: Some logging frameworks themselves have filtering ...


0

«Perhaps if we wrote programs from childhood on, as adults we'd be able to read them.» (Perlism #24) Understanding code, which is usually abstracted, often written to build a solution and not to best introduce a reader to it, and not filled with explanations, is inherently hard. You can't readily fix how other people write code, but you can work on your ...


6

I know this sounds a bit trite, but you become better at reading other people's code the same way you become better at anything else: practice and experience. It's a skill that you learn. It sounds like you don't have much talent (inherent ability) for it, but that can be overcome by practicing and working at it. Generally, if you can read your own code ...


0

It's a bit of a code smell, and your gut feeling is right about this not being a good solution. But instead of passing the arguments, extract the method and the three parameters into a separate class. This class takes the arguments in the constructor and exposes the one method. Something tells me that this one method is actually doing something that can be ...


2

If you remove the try block completely then you don't need the rethrow or the throw. This code does exactly the same thing as the original: public Configuration retrieveUserMailConfiguration(Long id) throws MailException { return translate(mailManagementService.retrieveUserMailConfiguration(id)); } Don't let the fact that it comes from more seasoned ...


6

The throw new RuntimeException("cannot reach here"); statement makes it clear to a PERSON reading the code what is going on, so is a lot better then returning null for example. It also make it easier to debug if the code is changed in an unexpected way. However rethrow(e) just seems wrong! So in your case I think refactoring the code is a better ...


32

First, thanks for udpating your question and showing us what rethrow does. So, in fact, what it does is converting exceptions with properties into more fined-grained classes of exceptions. More on this later. Since I did not really answer the main question originally, here it goes: yes, it is generally bad style to throw runtime exceptions in unreachable ...


50

This rethrow(e); function violates the principle which says that under normal circumstances, a function will return, while under exceptional circumstances, a function will throw an exception. This function violates this principle by throwing an exception under normal circumstances. That's the source of all of the confusion. The compiler assumes that this ...


4

I don't know if there's a convention. Anyhow, another trick would be to do like so: private <T> T rethrow(Exception exception) { // or whatever it actually does Log.e("Ouch! " + exception.getMessage()); throw new CustomWrapperException(exception); } Allowing for this: try { return ...


7

The throw was probably added to get around the "method must return a value" error that would otherwise occur - the Java data flow analyser is smart enough to understand that no return is necessary after a throw, but not after your custom rethrow() method, and there is no @NoReturn annotation that you could use to fix this. Nevertheless, creating a new ...


0

Plain and simple, a well developed IDE makes a programmer's job easier and faster. If the goal of a developer is to develop a product as fast as possible, then the product they're developing with speeding them up is a good thing. For instance, in Eclipse you can do stuff like: use a short cut to quickly find and open any class use a short cut to quickly ...


1

The main problem with IDEs isn't their crutchiness. Many people overestimate their advantages. Any decent programmer can learn to do quite well without one in a matter of weeks if necessary. Their main problem is their lack of portability, as you've discovered. Visual Studio is great if you happen to be developing on a Microsoft platform for a ...


3

It depends on what you call coding. If you consider coding to be an art, then if the computer is doing a part, that part wasn't the art. Personally, I have had maybe a cumulative total of 1 or 2 weeks worth of work in my programing career where my understanding of the underlying mechanics obscured by IDEs made me produce a better product. By that logic, ...


2

IDEs are a tool that programmers use to streamline common tasks. Even though yes, a programmer can and possible some do, avoid using them that would be analogous to avoiding using a wire stripper because I could just use my teeth. When software engineering was young most programs were relatively small and could easily be made in simple text editors. This ...


4

To answer your question: Are modern IDE's a 'crutch'? No. They are a tool. Here are a few other questions that might be relevant: "Can tools be used as crutches?" Sure. "Are all IDEs always used as crutches?" Nope. "Do some people use IDEs as a crutch?" Probably. "Will starting on crutches prevent somebody from reaching their full potential?" ...


2

I would suggest implementing command line parameters and command line help using argparse. The different functions could then be selected by command line options. If others without python installed need to use your program, then I would package it as an executable using pyinstaller. Pyinstaller can be used to build 3 possilbe executables: onefile, onedir ...


2

Have the 8 function calls wrapped in if __name__ == '__main__': Then you can call the script by running python NAME_OF_YOUR_SCRIPT.py If you need to pass any variables in when running it, use the argparse module


6

How often should RAII be used? As often as it makes sense to use (that is, whenever you have an operation that will need to be inverted/undone/closed/finalized/committed/etc. you should probably use RAII). However, I also know that you are supposed to create as few objects as possible, as to save RAM. No; This is a form of premature optimization ...


4

You wrote: The std convention is to have the last iterator point beyond the last element I think I can help your mental model by giving you two little replies (one section each). Don't think of it as beyond-last indexing, think of it as edge-based indexing Why edge-based indexing (right-open interval indexing) is nice Don't think of it as ...


0

You should keep conventions (definitions) used in a programming language. Example: #include <iterator> template< class Iterator> class Range { public: typedef typename std::iterator_traits<Iterator>::value_type value_type; typedef Iterator iterator; Range(const iterator& first, const iterator& last) noexcept ...


0

The standard library uses one-past-the end pointers for good reason - stick to this pattern. The alternative leaves no good way to describe an empty range. Also, unless you definitely need something different/special/written here, just use Boost.Range.


9

With your convention: every function in the algorithm library should be used changing the upper bound of the range and it can be quite error prone it isn't easy to represent empty sequences (this was Dijkstra's argument in Why Numbering Should Start At Zero). you can easily incur in off-by-one errors (e.g. when you take a partition of a collection). You ...


35

Follow the standard - the end is the iterator past the one you want. This allows you to use all the standard algorithms and containers without problem. It also means your users will be able to write the code they always have (eg for (x=startIt; x != endIt; x++) and this will work as expected. If you change this behaviour and set the last iterator to the ...


1

If you're just using plain old JDBC, you can do something like List<MyClass> results... while (rs.next()) { MyClass c = new MyClass(); c.setId(rs.getLong("THE_ID")); c.setName(rs.getString("THE_NAME")); .... results.add(c); } It's important that your class should not have any database related logic in it, that is, it should be a POJO ...


-2

There's a method using Reflection API. A quick tutorial is available in this link, While the implementation example for ResultSet can be seen here. However, be mindful of using Reflection API, since it automates a lot of things, debugging would be very difficult as it will look like that your code is working out of the box without having to do anything.


0

For completion purposes, allow a counter argument: https://michaelochurch.wordpress.com/2015/03/25/never-invent-here-the-even-worse-sibling-of-not-invented-here/ a mentality that I call "Never Invent Here" (NeIH). With that mentality, external assets are overvalued and often implicitly trusted, leaving engineers to spend more time adapting to the ...


1

The Principle of Least Privilege is about security, not software engineering and should not be confused with Encapsulation. They are two very different things. The point of the Principle of Least Privilege is to give a user (or application) the bare minimum of permissions it needs. So user A may get a different set of permissions than user B. This is to ...


4

In the examples you provided there is most probably no difference, since all the necessary conversions will most probably be performed at compile time. The following will incur a slight performance penalty: if( floatVariable > intVariable ) The penalty will be of the order of an additional clockcycle. (Maybe two? three clock cycles at most? that's ...


1

Is this good for the project? No. You have pointed out, yourself, that you have observed that it results in low-quality reports that are not targeted at required functionality, and that the testers end up, to compound the problem, scrambling to complete the work that they are actually "supposed" to be doing. If not, how can I (as a software ...


0

It's a BAD PRACTICE. A basic principle of software design: Don't hard-code configuration values inside your programs. This is especially true for anything that has a reasonable chance of changing in the future. The program code that you develop should be the same code that goes into any environment such as QA testing, UAT, and production. If somebody ...


1

What if I want to run the backend on my own machine but not on port 55793, for example if I were running multiple versions at the same time to compare them? What if I want to run the application backend on one machine, but access it from another? What if I want to add a fourth environment? As others have pointed out, you have to recompile just to change the ...


4

For one, (as others have mentioned) this is a bad idea because you're tying implementation details into your code. This makes it difficult to change things. As mentioned in this answer, if you want to add a new environment now you have to update your code everywhere, instead of just adding your program to a new environment. There is another serious flaw ...


13

You are absolutely right in thinking this is a bad practice. I've seen this in production code, and it always comes back to bite you. What happens when you want to add another environment? Or change your development server? Or you need to fail over to a different location? You can't because your configuration is directly tied to code. Configuration should ...


80

Code that works for you and is easy to maintain is by definition "good". You should never change things just for the sake of obeying someone's idea of "good practice" if that person cannot point out what the problem with your code is. In this case, the most obvious problem is that resources are hard-coded into your application - even if they're selected ...


0

I solved this problem once with something like this: class RelationshipManager { void addRelation(RelatableObject a, RelateableObject b); void removeRelation(RelatableObject a, RelatableObject b); List<C> getRelated(RelatableObject obj, Class<C> c); } The RelationshipManager keeps track of which objects are related to other ...


0

This works, but also introduces some side consequences of modifying the Group you pass, which you might not expect. But maybe this is the best (and relatively simple) way to do it? From a design perspective, to keep both lists in sync (if you want to handle it this way) is neither the responsibility of the player nor the group. You could design this ...


0

Your biggest problem is that you're creating circular references which can lead to a world of problems, from endless loops to memory leaks. In a database you'd create a separate entity (table) to contain the references, translated into code that's a class with a reference to both a Player and a Group. Iterating over a collection of those will then give you ...


1

First and foremost, determine what is more common in your system - to list groups of a specific player or to list players of a specific group. Depending on which case is more common, implement it accordingly. If you try to implement both equally, you will take a performance hit for both. So, assumption goes Player belongs to a group, so: public class ...



Top 50 recent answers are included