People usually invest in gold in two circumstances. One is when they fear inflation rates are eroding their spending power and they want an investment that they believe will hold its value better than cash. Another is when they see banks pay such low interest rates that gold seems to offer a better return on their investment than other options like savings accounts or bonds.
During the global economic crisis, many countries have sought to increase their gold holdings so they would not be left with too much of their reserves in hard currency that could lose value.But as the price of gold drops, buying gold looks like an increasingly unpredictable business. Russia, Turkey, Azerbaijan, and Kazakhstan all boosted their gold holdings in March this year.
Is there a limit to how much gold will fall?
Gold probably will find a floor fairly soon.The major rally in gold has come to an end. Any price appreciation in three-four years will be moderate. Investors should buy gold only if they can stay invested for at least 10 years.
In addition, the metal has lost its safe-haven appeal as risk appetite has increased due to improvement in the global economic outlook. Easing inflation in major economies has also diminished the demand for safe havens.
Gold has given a return of about +18% in last 10 years, however if we consider last 3 years the loss was about –11%. The gold might come further down as people has more options of investments like real state, education, infrastructure (unlike our grand parents have only one option to convert their savings into Gold). gold might continue to remain at its current position for next few quarters and might go down as well. So I suggest you to either wait for some more time before investing in gold. However you can invest in SIP manner with long term investment of around 10 years, as that would be a good option too.
This concept says, boolean take the default value and does not required any pre-assignment if at class level
How ever if it is a local variable ie defined inside the method then compilation error for uninitialized variable might occur.
If we do like :
boolean var = false;
Then it reassign the same value in 2 steps and make is much more slower.
1. Assign default value (false) to variable.
2. Assign user defined value to variable.
For better performance and clean code leave assignment to JVM
Let’s be real. The best ideas often don’t win. If you’ve ever been in a meeting with senior management, you’re likely familiar with this scenario: A roomful of employees listen to a loud and assertive executive pitch his new product idea—one that he claims will drive sales north. After his spiel, one person agrees “100 percent” with everything the exec says. Two or three people are reluctant to speak, scared to disagree or suggest better ideas, partly because their past ideas have been reprimanded.
THE FIRST Q: QUICK WINS
The first stage is to catch low hanging fruits, like identifying and removing dead code, removing duplicate code, and reduce method length. At this stage the following measures would be helpful:
- Cyclomatic complexity: should be 10 or below
- Average method length: 15 or below
- Code duplication for 3 (or greater) lines of code
- Overall code size: should be monitored and set targets for reducing it
THE SECOND Q: DIVIDE & CONQUER
The next stage is to start thinking of pulling apart components, whether business (or functional) components or utility components. This re-organization of code is essential to break the complexity of code and will open a large list of refactoring opportunities. At this stage, we will add the following two measures:
- Instability: to measure correct use of design layers
- Efferent and afferent coupling between component interfaces and the outer world
THE THIRD Q: BUILD QUALITY IN
The last stage is to start writing unit tests to test component interfaces. This is necessary so that to baseline the code quality and start doing more profound refactorings. At this stage, we will add the following measure:
- Unit tests code coverage
Refactoring : A change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior.
Code refactoring is the process of restructuring existing computer code – changing the factoring – without changing its external behavior. Refactoring improves nonfunctional attributes of the software. Advantages include improved code readability and reduced complexity to improve source code maintainability, and create a more expressive internal architecture or object model to improve extensibility. Typically, refactoring applies a series of standardised basic micro-refactorings, each of which is (usually) a tiny change in a computer program’s source code that either preserves the behaviour of the software, or at least does not modify its conformance to functional requirements.
I’ve been asked, “Is refactoring just cleaning up code?” In a way the answer is yes, but I think refactoring goes further because it provides a technique for cleaning up code in a more efficient and controlled manner. Since I’ve been using refactoring, I’ve noticed that I clean code far more effectively than I did before. This is because I know which refactorings to use, I know how to use them in a manner that minimizes bugs, and I test at every possible opportunity.
Like refactoring, performance optimization does not usually change the behavior of a component (other than its speed); it only alters the internal structure. However, the purpose is different. Performance optimization often makes code harder to understand, but you need to do it to get the performance you need. Most of the the time refactoring improves performance in terms of speed as well, however at times its inverse could happen ie by extracting too many classes and introducing too many variable could have an impact of performance as well.
I want to reiterate that refactoring does not change the observable behavior of the software. The software still carries out the same function that it did before.
One thing at a time with TWO HATS ( Refactoring Vs Adding feature )
When you add function, you shouldn’t be changing existing code; you are just adding new capabilities. You can measure your progress by adding tests and getting the tests to work. When you refactor, you make a point of not adding function; you only restructure the code. You don’t add any tests (unless you find a case you missed earlier); you only restructure the code. You don’t add any tests (unless you find a case you missed earlier); you only change tests when you absolutely need to in order to cope with a change in an interface.
As you develop software, you probably find yourself swapping hats frequently. You start by trying to add a new function, and you realize this would be much easier if the code were structured differently. So you swap hats and refactor for a while. Once the code is better structured, you swap hats and add the new function. Once you get the new function working, you realize you coded it in a way that’s awkward to understand, so you swap hats again and refactor. All this might take only ten minutes, but during this time you should always be aware of which hat you’re wearing.
Please note that testing the while refactoring is very import. Always make small changes, test them commit them and make other changes. Do not thing to make all changes in a singe go and later on test entire application at the end. Multiple small cycles of refactor– test – refactor –test and smile is better then big refactoring – final testing – crying
Download the working example demo code in java from my GIT repository -
Example Code Description :
1. Date interpreter example : The main cause of Y2K virus was interpretaiton of date format, in this example code I tried to address the same so that system can intrepret any date given in any formats. we have a interpreter for DD, MM and YYYY (rule to pick the date from context) so you provide the format and system gives you the conversion. Straight forward.
2. And Or Expression : This example taks a string where in it should match the expression based on rule which accomplies And / Or expression. Code is simple and small but a bit triky to get hold of. Feel free to downlaod and play with it.
- Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.
- Map a domain to a language, the language to a grammar, and the grammar to a hierarchical object-oriented design.
This interpreter design pattern does not give solution for building a whole large interpreter for a language. It can be applicable for smaller chunks where grammar and interpretation is applicable. We can consider scenarios like regular expressions and interpreting mathematical expression.
The Interpreter pattern discusses: defining a domain language (i.e. problem characterization) as a simple language grammar, representing domain rules as language sentences, and interpreting these sentences to solve the problem. The pattern uses a class to represent each grammar rule. And since grammars are usually hierarchical in structure, an inheritance hierarchy of rule classes maps nicely.
An abstract base class specifies the method
interpret(). Each concrete subclass implements
interpret() by accepting (as an argument) the current state of the language stream, and adding its contribution to the problem solving process.
The Intepreter pattern defines a grammatical representation for a language and an interpreter to interpret the grammar. Musicians are examples of Interpreters. The pitch of a sound and its duration can be represented in musical notation on a staff. This notation provides the language of music. Musicians playing the music from the score are able to reproduce the original pitch and duration of each sound represented.
- Decide if a “little language” offers a justifiable return on investment.
- Define a grammar for the language.
- Map each production in the grammar to a class.
- Organize the suite of classes into the structure of the Composite pattern.
- Define an
interpret(Context)method in the Composite hierarchy.
Contextobject encapsulates the current state of the input and output as the former is parsed and the latter is accumulated. It is manipulated by each grammar class as the “interpreting” process transforms the input into the output.