Campbell Ritchie wrote:
That only applies to “dead” languages like ancient Latin and ancient Greek. Which is why the translations all sounded so wooden. I had the good fortune to be the first year to be taught French from audiotapes and film strips (now that takes you back) and not to try learning French from a book.Julian West wrote:. . . ...and nobody is taught composition in grammar school; we are taught grammar first. . . .
We experience the difficulty people have in making the leap from procedural programming to objects, and see that so many people never make it. Those of us who had the good fortune to be taught by somebody who understands OO appreciate the difference.
Junilu Lacar wrote:NOTE: This thread was split off from here: https://coderanch.com/t/670933/java/java/Highest-card
Campbell Ritchie wrote:There is something very non‑object‑oriented about your code. Java® is supposed to be an object‑oriented language an so many people appear here who appear to be bein gtaught procedural programming.
Julian West wrote:Campbell: One doesn't start programming learning classes and OOP principals first; one begins with the basics: variables, conditional statements, and flow-control. "Parts of speech" precedes "composition".
Asking someone to write a program is more like asking them to write an essay though, isn't it? To write a good essay, one needs to include composition. I see objects as being somewhat analogous to paragraphs. They sit on the fence between "parts of speech" and "composition" because they are about both "form and structure" and "organization of ideas".
Campbell Ritchie wrote:
That is what lots of people think, but it is not how I was taught Java®. It is really easy to get into a procedural style because procedural programming looks like school algebra. And many people find it very difficult to get out of a procedural style.Julian West wrote:. . . Campbell: One doesn't start programming learning classes and OOP principals first; one begins with the basics: variables, conditional statements, and flow-control. "Parts of speech" precedes "composition". . . .
Campbell Ritchie wrote:
It is not that it “knows” anything specific about Period, but that dangerous confusion can arise from calling static methods on instance names.Julian West wrote: . . .
...and IDEs know this and warn "Accessing static method OfWeeks"
Gheyath Nasani wrote:
Julian West wrote:
Campbell Ritchie wrote:
The quote from the Sybex book explains that if you chain method calls with Period, you get the wrong result.
...and IDEs know this and warn "Accessing static method OfWeeks"
I am well aware that IDE know this and warn "Accessing static method OfWeeks". But my question about "What is problematic when accessing static method ofWeeks ??
Campbell Ritchie wrote:
The quote from the Sybex book explains that if you chain method calls with Period, you get the wrong result.
Vroomfondel wrote:“We demand rigidly defined areas of doubt and uncertainty!”
Sybex OCA8, pp.146-147 wrote:There are fve ways to create a Period class:
Period annually = Period.ofYears(1); // every 1 year
Period quarterly = Period.ofMonths(3); // every 3 monthsWorking with Dates and Times 147
Period everyThreeWeeks = Period.ofWeeks(3); // every 3 weeks
Period everyOtherDay = Period.ofDays(2); // every 2 days
Period everyYearAndAWeek = Period.of(1, 0, 7); // every year and 7 days
There’s one catch. You cannot chain methods when creating a Period. The following
code looks like it is equivalent to the everyYearAndAWeek example, but it’s not. Only the
last method is used because the Period.ofXXX methods are static methods.
Period wrong = Period.ofYears(1).ofWeeks(1); // every week
This tricky code is really like writing the following:
Period wrong = Period.ofYears(1);
wrong = Period.ofWeeks(7);