| [+] Programming Diversions » Competition : Win a ticket to GeeCON Prague 2014 (Go to) | | Campbell Ritchie |
Adalberto Toledo wrote:that library is only used in the Main method Noted. Solution accepted. |
| [+] Programming Diversions » Competition : Win a ticket to GeeCON Prague 2014 (Go to) | | Campbell Ritchie |
Joe Harry wrote:I can already see that my obfuscated version fails the test for a String input Of course, I can obfuscate it further and fix it. Is it necessary? No. The Rules wrote:The sentence is a String delimited by single whitespace characters. Assume no punctuation. That means you don't have to handle multiple whitespace. You can assume it never happens. As a general note to all. Please don't forget to UseCodeTags when posting code. Omitting their use does not qualify as a valid obfuscation technique. |
| [+] Programming Diversions » Can't get tests to pass for the GeeCON comp programming challenge (Go to) | | Tim Cooke |
But by not entering at all you are guaranteeing you won't win. What have you got to lose? Remember, you can enter more than once if you want to. |
| [+] Bunkhouse Lounge » Book Club - October 2014 : "The Pragmatic Programmer" by Andrew Hunt, David Thomas (Go to) | | Tim Cooke |
October is upon us, so let's get those Pragmatic Programmer discussions rolling. |
| [+] Programming Diversions » Can't get tests to pass for the GeeCON comp programming challenge (Go to) | | Tim Cooke |
Hello adam, welcome to the Ranch I moved your question out of the main competition thread so we could have some discussion about it on the side. Once you have it working and are happy with it then you are more than welcome to submit your new solution to the competition thread again. Now, back to your question: You are so very close. Observe that the tests are inspecting the data being returned from the wordOccurrence method, they are not inspecting what is being output with System.out.println. So have a think about what you need to do with wordMap at the end of the method. |
| [+] Programming Diversions » Competition : Win a ticket to GeeCON Prague 2014 (Go to) | | Campbell Ritchie |
Pawel Szulc wrote:I've entered the competition but I still am amazed that you promote "unreadable" code. Hi Pawel. None of us here at the Ranch would ever promote that you write unreadable code in the real world. But for this competition we wanted to make it fun and interesting by getting you thinking a little differently and have you write the most obscure code you can come up with that still solves a simple problem. @Joe Harry, You can enter as many times as you like, so go nuts. |
| [+] Programming Diversions » Competition : Win a ticket to GeeCON Prague 2014 (Go to) | | Campbell Ritchie |
Joe, remember the rules: Java SE only. No third party libraries allowed.Must compile and run with Java8 JDK and JRE That means no Scala. Sorry Joe. |
| [+] Programming Diversions » Competition : Win a ticket to GeeCON Prague 2014 (Go to) | | Campbell Ritchie |
Joanne Neal wrote:one that's a first post from someone who registered two and a half years ago. Yea who does that! ( ActiveStaff#timcooke) Tim Cooke wrote:Tim joined CodeRanch in 2008 but didn't post a single thing until early 2013. Nobody knows why Remember, obfuscation is the name of the game in this competition. We're looking for the most unreadable code you can muster while being functionally correct. |
| [+] Programming Diversions » Competition : Win a ticket to GeeCON Prague 2014 (Go to) | | Campbell Ritchie |
CodeRanch is offering 1 free ticket (yes, a free ticket!) to GeeCON Prague 2014 which is scheduled for 23 - 24 October 2014. The event boasts Java and JVM based technologies, dynamic languages, enterprise architectures, patterns, distributed computing, software craftsmanship, mobile and much more... To stand a chance of winning the ticket, all you have to do is enter our fun programming competition, posting your solutions in this very thread. You can even post more than once. The solution that we, the CodeRanch staff, think is the best will win the ticket to GeeCON Prague 2014. Also, as an added bonus, the winner will have the opportunity to meet one of our esteemed Marshal's Ulf Dittmer who will be attending the conference too. The contest ends Friday 10th October, with the winner announced by Saturday 11th October. Good luck, and have fun!! The Competition: Java obfuscated word occurrence counter The Problem Write a program that takes a sentence, a String with words delimited by whitespace, and returns the occurrence of each word as a Map of words (key) to occurrence count (value). The Criteria Write a program that solves the problem, while being as unreadable to the human eye as possible. (Obfuscation)Bonus points for achieving it in the least amount of code. (Code Golf) The Rules The sentence is a String delimited by single whitespace characters. Assume no punctuation.Words are case insensitive. "CodeRanch" is the same as "coderanch"Words are mapped in lowercase form. "CodeRanch" is mapped as "coderanch"Java SE only. No third party libraries allowed.Must compile and run with Java8 JDK and JREMust comply with the following method signature For example The sentence (String) "I really REALLY love CodeRanch" returns the occurrence (Map) {i=1, really=2, love=1, coderanch=1} A test harness to get you started Provided is a simple Java class with the skeleton method signature and a couple of tests that you can use to verify the correct functionality. For writing your solution you are only interested in the method skeleton on lines 6 - 9, this is where you complete the method with your solution to make it function correctly. How to run the test harness Take a copy of this code and paste it into a file called GeeConComp.java. Compile it javac GeeConComp.java Run it java GeeConComp Initially the output will report test failures, which is expected as the solution has not been written yet. CodeRanch GeeCON Prague 2014 competition ======================================== Test FAIL :( Expected: {love=1, coderanch=1, i=1, really=2} Actual : null Test FAIL :( Expected: {better=3, never=1, rest=1, may=1, and=1, i=1, best=2, until=1, is=1, my=2, good=2} Actual : null What you want to see is passing tests CodeRanch GeeCON Prague 2014 competition ======================================== Test PASS :) Test PASS :) That's it! Enjoy. |
| [+] Jobs Discussion » Should I refer to my temporary contract as reason to apply for a job? (Go to) | | Jan de Boer |
Contracts are often of fixed duration so I don't see that any negative implication can be drawn from the fact that your contract has a fixed termination date. I would see that as a perfectly good reason to be looking for another job. |
| [+] Java in General » Mock internal method with JUnit and Mockito (Go to) | | Vani Kumar |
It's recommended that you UseCodeTags when posting code. I added them for you this time, see how much better it looks? Did you read through that other thread I referenced yesterday? There's an answer in there that shows you how to 'mock' out calls to methods in the same class. |
| [+] Java in General » Mock internal method with JUnit and Mockito (Go to) | | Vani Kumar |
| |
| [+] Bunkhouse Lounge » Clean Code : Who follows the boy scout rule? (Go to) | | Junilu Lacar |
You raise an interesting point Bear. 'Cleaning up' production code without test coverage is risky, and often too dangerous to justify the perceived benefit. However, it is my view that the test suite is as important a part of the codebase as the production code itself so I would consider that writing a regression test for some uncovered code is a valid improvement even if you don't change the prod code. |
| [+] GNU/Linux » new security vulnerability in BASH (Go to) | | Jeanne Boyarsky |
ksh user smugness reaches unbearable new heights... |
| [+] Bunkhouse Lounge » Book Club - October 2014 : "The Pragmatic Programmer" by Andrew Hunt, David Thomas (Go to) | | Tim Cooke |
Howdy folks, Welcome to the Bunkhouse Lounge! This is where we come to talk about our favourite books, discuss what we like, don’t like, don’t understand, anything at all. There’s enough room for everyone so drop in and make yourself comfortable. For the Month of Ooctober we are inviting you to read Andrew Hunt and David Thomas' “The Pragmatic Programmer” with us. Grab yourself a copy and join in the discussions! Thinking of buying a copy from Amazon? Support CodeRanch by using this referral link: - Amazon (US) : The Pragmatic Programmer: From Journeyman to Master by Andrew Hunt, David Thomas |
| [+] Meaningless Drivel » Bear opened the door... (Go to) | | Chris Barrett |
I wonder what kind of bear it was?  |
| [+] Ranch Office » Gotta love that hospitality here (Go to) | | Tim Holloway |
Hello Sooraj, I'm glad you have been made to feel welcome. We do our best so thanks for letting us know how we're doing. |
| [+] Beginning Java » generate an output pattern (Go to) | | chrstian ferma |
Joanne, I think we are both correct. The behaviour for when n does not equal 9 is undefined so both of our solutions could be argued to be correct. However, before we get off an a tangent, I threw in that somewhat glib response to highlight the fact that you have not specified your problem enough to be able to write a complete solution for it. A point that Fred has made in a more straightforward manner. Another point to not is that we are NotACodeMill, which means that nobody is going to give you the solution. What we will do is help and guide you into solving the problem yourself. That's how we learn. |
| [+] Beginning Java » generate an output pattern (Go to) | | chrstian ferma |
How's about this? I believe it satisfies your requirements. |
| [+] Java in General » String split with white space (Go to) | | Campbell Ritchie |
Along with the others I invite you to have a go at this yourself first. However, I have found a couple of contradictions between your requirement and example. suresh dhanapal wrote:want to wrap in two lines if the length is >15 Expected: New York Language Center-Bronx,Inc You say you want to wrap if the line length exceeds 15 characters, but "New York Language" is 17 characters. "Center-Bronx,Inc" has no whitespace to wrap on but the 'word' is 16 characters and you don't define what you want to do in this scenario. |
| [+] Java in General » IllegalArgumentException vs NullPointerException (Go to) | | Tim Cooke |
I would favour a NPE for a null param, and an IAE for a non-null param that's incorrect for the domain. However, consistency is key so if I were working with a codebase that threw IAE's for null params then I would continue to do so. As a point of note, Effective Java summarises the occasions for use for commonly reused exceptions: Effective Java wrote:NullPointerException : Parameter value is null where prohibited. IllegalArgumentException : Non-null parameter value is inappropriate. The Google Guava Preconditions library that Jesper mentions follows this convention with its checkNotNull() and checkArgument() functions, which throw NPE and IAE respectively. |
| [+] Beginning Java » Getting some errors - java out of date? (Go to) | | Campbell Ritchie |
| |
| [+] Web Services » web services thesis (Go to) | | Tess Jacobs |
At Master's degree level I would be expecting your dissertation to demonstrate some improvement or advancement to a particular field of study. I'm not sure a research study on an existing and well established technology such as REST is going to be enough. I guess you should talk to your supervisor about it though as he or she will be able to give you a definitive answer on that. Did your University department not provide you a list of projects that you could choose from? I know my CS department did for my Master's degree. Was there nothing on there that took your fancy? |
| [+] Functional programming » Coursera: Functional Programming Principles in Scala (free online course) (Go to) | | Guillermo Ishi |
Guillermo Ishi wrote:as long as it will keep letting me use mutable variables ... and by doing so you will miss one of the key techniques of Functional Programming. Try to let this one go and open your mind to all of what's being taught on the course. |
| [+] OO, Patterns, UML and Refactoring » What is the way to learn the concept through Java API? (Go to) | | Campbell Ritchie |
I'm not entirely sure I understand the question, but if you're just asking if Oracle provide any documentation or tutorials for the Java language and libraries then the answer is yes: Oracle Java Tutorials |
| [+] Meaningless Drivel » Gun. To shoot currency. At strippers (Go to) | | Jan de Boer |
The internet is a dangerous place. You're never more than a couple of clicks away from something super unpleasant. This is especially true on YouTube. |
| [+] Meaningless Drivel » Gun. To shoot currency. At strippers (Go to) | | Jan de Boer |
It does beg the question: How did you find this? |
| [+] Beginning Java » Am I Just Bad At Java? [Java Rant] (Go to) | | Campbell Ritchie |
Brian Stumbaugh wrote:Im sorry....but whether your teacher is right about most of the class dropping out or not.....thats not something you should say to your students. This is getting slightly off topic, but I'll play along. I think this is a fair enough thing to say. You are invoking two sets of reactions from students: (a) "Well if I'm probably going to fail anyway then what's the point of wasting my time doing the work" (b) "Oh crap, this stuff is going to be hard. I'd best work really hard to make sure I succeed" If you fall into category (a) then please drop out now. I don't want to see you at an interview for a graduate programmer position. If you fall into category (b) then come knock on my door when you're finished because I want to talk to you. Being able to keep yourself focused and motivated in the face of probable failure is a big part of what it means to be a successful programmer. If difficult programming problems had a straight forward, guaranteed to work, solution then it would have been done already a thousand times over. The flip side to this discussion is the reputation of the educational institution itself. They need to make sure the quality of their graduates is high so they don't want their courses to be easy enough for anyone to get through without really having to work for it. |
| [+] Testing » mockito question, I guess its not possible to verify this->method (Go to) | | Tim Cooke |
I'll go on anyway, because it's an interesting technique. Starting with the production code Mockito, and the like, don't provide you the ability to do verifications on local instance methods but we can do it ourselves by creating a testable version of the class you want to test. We do this by creating a subclass that overrides the collaborator methods and provides access to inspect whether those methods have been called. We'll need to change the scope of the private collaborator methods from private to protected but that's a minor sacrifice compared to the gains of having your code in a test harness. Here's the prod code again with the modified accessors. Now here's the test case with a testable version of the prod code as an inner class that we use to make assertions on whether those local methods get called. The test will fail if either of the methods are not called. From here it's not difficult to change it to make assertions on the order and frequency in which the collaborating methods are called. Does that help you with your problem? |
| [+] Testing » mockito question, I guess its not possible to verify this->method (Go to) | | Tim Cooke |
I think I get it. Here's a scenario that I come across from time to time. You want to test that doTheFirstThing() and doTheSecondThing() are called? Is the order in which they are called important? Please confirm this is what you're after before I go on. |
| [+] Testing » mockito question, I guess its not possible to verify this->method (Go to) | | Tim Cooke |
It's not quite clear what you're asking here. perhaps an example might be a good idea. I assume that "->" is your pseudo-code notation? If you're asking about Java then keeping with the syntax of the language goes a long way to convey meaning. This is where a runnable example comes in handy. |
| [+] Lambdas and Streams » Java 8 Virtual Machine (Go to) | | Tyler Lusk |
Perhaps they are 'essential' for getting the best out of a minecraft application. But that doesn't mean they are the best for all other applications. JVM tuning is a worth while activity but there's no 'one size fits all' config that works for every application. |
| [+] Beginning Java » Am I Just Bad At Java? [Java Rant] (Go to) | | Campbell Ritchie |
Cow worthy advice from Chris there. Graham, you've gotten some top advice here today so please don't be disheartened by the initial complexity of learning programming from scratch. It is difficult but if you have the passion for it then stick with it and you'll be fine. Challenges are exciting, enjoy them. We've all been where you are now and made it though, so you can too. |
| [+] Beginning Java » Core Java: auto-increments (Go to) | | Campbell Ritchie |
| |
| [+] Lambdas and Streams » Java 8 Virtual Machine (Go to) | | Tyler Lusk |
Nope. What makes you think they are necessary? |
| [+] Meaningless Drivel » SSD drives - any comments? (Go to) | | J. Kevin Robbins |
To be honest Winston, if your iMac is just 3 years old then it's probably just fine the way it is now and it might even already have an SSD in it or some hybrid drive which I know Apple used for a while too (hybrid meaning that it was part SSD, part mechanical). If it were me I wouldn't be in that much of a hurry to upgrade it at all. I have an iMac too, the original 2009 27" version, and I know that the only way in is though the glass screen on the front. I'm not brave enough to do that myself. If I broke it I would actually cry. So if your iMac turns out to be just fine already then your only worry now is having somewhere to safely put those media files. Turning your other deskop into a NAS might just be the answer for that. Now that I have my NAS box set up and running I have it stashed under my study desk with just power and network attached to it, no monitor, keyboard, or mouse required. It's a tidy solution and makes good use of an otherwise useless machine. As far as software goes, Joe is right, you can get anything you need. Eclipse is available, as is IntelliJ. A few "what's the Mac equivalent of x, y, and z software?" questions in the Mac OS forum will have you up and running in no time at all. |