Tag Info

Hot answers tagged

15

This sounds suspiciously like an inner platform. Here are the potential problems: You'll be writing queries that query the database for what information to query (metaqueries) first, rather than queries that simply retrieve the needed information. You'll be subverting the role of the database, which already provides metadata capabilities such as rows, ...


12

Another option is to return a result object instead of basic types. For example: OperationResult deleteResult = myOrm.deleteById(id); if (deleteResult.isSuccess()) { // .... } With this, if for some reason you need to return the numbers of rows affected, you simply can add a method in OperationResult: if (deleteResult.isSuccess()) { ...


11

Returning the number of affected rows is better because it gives additional information about how the operation proceeded. No programmer will blame you because he/she has to write this to check if they got some changes during the operation: if(affectedRows > 0) { // success } else { // fail } but they will blame you when they'll have to know ...


9

I would not recommend any of them. Instead, return nothing (void) on success and throw an exception on failure.


8

I'm going to start flat out by saying after more than 30 years experience writing software and working in I.T in general, I have NEVER, EVER yet found a good reason for concatenating data coming out of a database. You could be putting 90% of your application code in the DB infrastructure, and doing all sorts of magic things with it, and I still would not be ...


6

would you consider wrapping a function with a different name just to clarify it's behavior in certain situations a good practice? Absolutely. The key thing here is that for almost all code, the interface matters more than the implementation. If it makes sense to have a Restart method in your interface, then add it. Because while it's true that for ...


6

Is the duplication of classes ever useful/good design? Its good practice to have a separate view model class for use in the UI layer rather than using the same class that's used in the data layer. Your UI/web page might need to display other bits of information that aren't strictly related to the data entity. By creating this extra class, you are ...


5

If you are working solo. Here are the advices: Do as little low-level work as possible. Use as much library and tools as you possibly can including things you think you can easily code (don't do it, just use the library). Take the top-down approach. Only code things that you really need. When you see a problem in abstract term, search on google and use ...


4

I'd prefer the second approach, but with a better variable name. Don't repeat the logic for obtaining the manager (DRY). If this changes, you'll only need to change one place instead of three. Decouples the logic of operating on the manager from obtaining the manager. Extracting it to its own method is only a small step. Assuming you use a good name (not ...


4

Catch the exception at the level where you do have the file name, incorporate the file name into the error message, and rethrow. This is a classic example of why exceptions are designed the way they are; they propagate up the call stack to the next available catch clause, where new information can be added to them where it is available. This avoids the ...


3

Large software products start out as small software products and feature creep from there until it does everything the customer wants it to. Rarely are large products made ex nihilo. Start small - very small - and increment. You write the smallest simplest thing you can that works in the realm. Inventory tracking for example. Just write some code that ...


3

By some definitions, a class is a type (or a structure) that provides implementation and interface (assuming it's not an abstract class) for some specific sub-set of a problem. With that in mind we can say that most sensible way of organizing and naming class would be to divide them logically. In your given example the classes could be: Message Session ...


3

If you're using a logging framework like Log4j, you can use a nested diagnostic context (NDC) to store the file name at the point it is available, then retrieve from the NDC at the time you log the messages. Logj4 NDC This can be even more useful because you can actually write a log4j appender that handles log messages specially based on the NDC content. ...


3

You can't make new functions "built-in" to C without changing the compiler. However, you can write and extend libraries with new functions that your programs can then reuse wherever they want. For that, you need to compile a library with the functions, your program needs to include the library header file, and the linker has to include the object code for ...


2

It depends on whether foo() and B() lie on the same level of abstraction. If they do, then Option A is preferable. Otherwise (foo() is an implementation detail of B() and therefore lower than B()) Option B is better. So, the guiding principle here is: don't mix levels of abstraction.


2

There is a deeper issue here: the fact that C# and Java insist most/all types must be distinguishable by name rather than structure: e.g. class MyPoint2D and class YourPoint2D are separate types even if they have the exact same definitions. When the type you want is "some anonymous thing with an x field and a y field" (i.e. a record), you're out of luck. So ...


1

The only way to get access to all those systems is to earn the TRUST of their creators/owners. And I can tell you right now that you're not going to get that trust as a one person hobbyist or startup with no background in the field. That's highly sensitive private and financial information you're talking about, data that needs to be seriously protected. Your ...


1

1) The page that will be displayed contains MANY anchor tags, if that's embedded in an iFrame, what happens if the user on THEIR website clicks the link in the iFrame? Does the iFrame page change, or does their ENTIRE page change? Iframes are self-contained websites. As such, any links inside the iframe will change only the contents of the iframe, ...


1

"Is this better than that?" is not a useful question when the two alternatives don't do the same thing. If you need to know the affected row count, then you must use version A. If you don't have to, then you can use version B - but any advantage you might gain in terms of less code-writing effort is already gone since you took the trouble to post both ...


1

Return an array of Optional. That aside, you might want to consider better collections than arrays; they're quite cumbersome, especially since they don't implement Iterable or Collection. EDIT: For catching the type of the error, your Result<T> is a good starting point, but I wouldn't expose both fields like that (I assume you only did that to get the ...


1

You can allow the user to atomically select and "softly" lock the record by adding a timestamp to the record with when it was locked or when it will be unlocked. You prevent locked records being accessible by excluding them based on the time at locking and the lock field. Manual unlock (for a rollback/cancel) can be implemented by setting the timestamp to ...


1

Chained methods are awesome, but I almost always go for the variable approach. Other than what CodesInChaos already mentioned, it's just a lot quicker to interject some code and do some debugging / error handling. For example, in your code it would probably make sense to check if you've actually instantiated the Entity Manager before you start using it: ...


1

Your UI should tell the database layer what operation to perform. In the UI, you will obviously have two buttons, one which says "Create new Person" and the other saying, "Edit this Person". So you already know what action needs to be performed. When you invoke the UI Dialog, pass in this state (Add or Edit) to the dialog. Then, based on the value of this ...


1

In general, I'm against writing a method with a semantically different name that simply calls another method but does not have different behavior, unless you're implementing the Adapter Pattern. The only way this might makes sense is if you name the method something like: restartSignalIsReallyJustAStart() which completely explains what you're doing ...



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