• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Doubts about the implementation of the visits of a graph implemented with adjacency lists

 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alicia Perry wrote:However, I'm realizing how important it is to think before you write the code:...


And just one final point: there's a simple exercise you can go through to help with "what not how".

1. When you get given a complex set of instructions, don't start thinking about Java, or even what needs to be done. Clear your mind.
2. Sit down with your instructions and read through them. Several times; until you know them back to front. Make notes about anything you don't understand, and make sure you get clarification on them before you proceed any further.
3. Read through them a few more times, noting down all the major verbs and nouns (keep two separate lists), and keep doing that until you're fairly sure you have them all. If, as in your case, the instructions contain stuff about actual classes or methods you need to implement, put the classes and interfaces in the "nouns" column, and methods in the "verbs" column. You might even annotate them with a "(C)", "(M)" or "(I)" to remind yourself that they're required exactly as specified, but don't forget to include all the other English nouns and verbs you find as well.

It's called "lexical analysis" (or some silly term like that), and it can be a really good 'first cut' in the "what" process, because it helps give you an idea of what you're likely to need. It's not foolproof, by any means, and you'll find that you get better at it with practise. But the important thing is NOT to think about how these "things" are going to work while you're doing it. It's a simple extraction process; nothing else.

Once you have your lists, the nouns will generally equate to classes or events, and verbs to methods or actions. It's not a 100% rule, but it's usually pretty close. What you'll also find is that many nouns will fit with an existing Java class: for example, a "number" will probably equate to an Integer or a Double, and a "list" to some sort of Java Collection, but don't start thinking about that yet. You're simply gathering information at this stage.

Then start linking verbs with their associated noun(s), which may mean reading through your instructions again to understand the context. You can even start writing rudimentary method signatures based on whether nouns are the subject or object of a verb, so a phrase like "put the value in the list" might become something like:
list.put(value)
but again: don't make them look too much like Java yet. You're analysing, not coding.

It's inevitable of course that some "how will I do this?" thoughts will be going through your mind, but try to keep them at bay for as long as possible. What you'll find is that the simple act of making these lists, and refining them, and connecting the verbs and nouns, gradually starts to give you the structure of your problem, so that when you start the process of translation to Java, you'll have a much better idea of the classes you're going to need and the methods they'll need to implement.

And when you DO start that process, you may well find the WhereDoIStart page worth a read, because it describes a technique called "stubbing" which is really useful to know. Basically, it allows you to write a class that compiles, but does absolutely nothing; rather like an interface. Sound stupid? Well it isn't, because it allows you to build up that class gradually, and concentrate (more or less) on one thing at a time.

Hope it helps, and good luck to you.

Winston
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Are you trying to understand recursion? I gave up trying to understand it ages ago. It just seems to work!


Yeah. As they say: To understand recursion, you must first understand recursion.

Winston
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic