Throw away a request if any of the IF statements are false

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 2275 Views - Last Post: 24 February 2015 - 05:38 AM Rate Topic: -----

#16 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6505
  • View blog
  • Posts: 14,360
  • Joined: 02-June 10

Re: Throw away a request if any of the IF statements are false

Posted 18 February 2015 - 05:00 PM

Stop. Stop typing.

Show me your design plan. Do you have any diagrams where you have planned out the classes and interaction? In other words, before you write the dialog for this play do you even know who the actors are?
Was This Post Helpful? 0
  • +
  • -

#17 Premier2k  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 200
  • Joined: 26-August 08

Re: Throw away a request if any of the IF statements are false

Posted 19 February 2015 - 01:22 AM

Nope, I have no idea is the simple answer to that. I don't have a plan for what I'm building I'm just trying to learn how to build it right. Maybe I'm going about it the wrong way but how do I learn to build something correctly?

Maybe I do need to understand what I'm building and design it correctly, but I don't know how to design applications using diagrams showing classes, members and interactions. Is that something Visual Studio can help me with or is that done on paper?

Maybe if I knew that then I could do this better. The issue I have is, where do I learn this stuff? What can I type in to a search engine to bring back something that will help me.

There is a saying that is very applicable here, "I don't know what I don't know."
Was This Post Helpful? 0
  • +
  • -

#18 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6505
  • View blog
  • Posts: 14,360
  • Joined: 02-June 10

Re: Throw away a request if any of the IF statements are false

Posted 19 February 2015 - 05:13 AM

I get that. Really I do. Let me ask you this... Have you worked through the tutorials in this list?

Tutorials I recommend:


Was This Post Helpful? 0
  • +
  • -

#19 Premier2k  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 200
  • Joined: 26-August 08

Re: Throw away a request if any of the IF statements are false

Posted 19 February 2015 - 05:43 AM

I'm going to go through every one of these tutorials. I'm actually subscribed to Pluralsight and CodeSchool which I find really good resource sites but it doesn't hurt to look at fresh tutorials from somewhere else.
Was This Post Helpful? 0
  • +
  • -

#20 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6505
  • View blog
  • Posts: 14,360
  • Joined: 02-June 10

Re: Throw away a request if any of the IF statements are false

Posted 19 February 2015 - 07:11 AM

View PostPremier2k, on 19 February 2015 - 02:22 AM, said:

Nope, I have no idea is the simple answer to that. I don't have a plan for what I'm building I'm just trying to learn how to build it right. Maybe I'm going about it the wrong way but how do I learn to build something correctly?

Maybe I do need to understand what I'm building and design it correctly, but I don't know how to design applications using diagrams showing classes, members and interactions. Is that something Visual Studio can help me with or is that done on paper?

Maybe if I knew that then I could do this better. The issue I have is, where do I learn this stuff? What can I type in to a search engine to bring back something that will help me.

There is a saying that is very applicable here, "I don't know what I don't know."


Start with the idea that coding is as much art and style as science. That makes you, the developer, part scientist and part artist. So you have a lot of freedom to do things the way that work for you. Don't worry so much about using the *right* technique or the *right* planning software. Some people use dedicated UML diagram programs. Some use Excel. Some use Visio. Some use bar napkins and markers. Me... I like whiteboards.

Your diagrams don't have to be perfect. They don't even have to be diagrams. They don't have to be of a single style. But what your planning does need to be is... Existent. You have to actually plan before you start typing. It doesn't matter if its a UML diagram or a pages in a 3-ring binder. We're going to do some basic planning right here in a web post (text document of sorts), so clearly it doesn't matter what you use as long as it works for you.

So lets plan this together. Some of this may sound like my classes tutorial. Oh well.
Objects in code should mimic objects in the world. If you are going to build a movie tracking program like this then what are the objects?

Movies... People(actors, directors, etc.)... Genre (horror, sci-fi, mystery...)
These are all objects... Not just strings for their names. They are objects. If the only property they have is a name then so be it. But C# is an object oriented language. If you make classes for each thing you have the ability to upgrade the thing later to have more properties. If you just use a string as the actual movie ("Star Wars") then how much upgradeablity do you leave yourself?

So what are the properties of a movie?

class Movie
------------------------
string: Title
DateTime: ReleaseDate
TimeSpan: Duration
Language: Primary language it was filmed in
Collection: Locations (where was it filmed)
Collection: Actors
Collection: Writers
Collection: Directors
Collection: Producers
Collection: Production company
Collection: Genre (yes, a collection.  A movie can be a comedy and a drama, or action and sci-fi)



Hmmm.... Actors, writers, directors... They're all people, right?
So I guess we could make a Person class. Then inherit from that for each type.

class Person
-------------------------
string: LastName
string: FirstName
string: MiddleName
DateTime: Date of birth
location: Place of birth
Collection: Milestones (events in the person's timeline/life/history)
Collection: Movies
---------------------------
class Actor : Person
class Director : Person
class Writer : Person



The thing to remember here is that you don't have to plan to the Nth degree at this time. You've stubbed out some objects. If it suddenly dawns on you that you want to add something to a person you can do that 6 months from now.

class Person
-------------------------
string: LastName
string: FirstName
string: MiddleName
DateTime: Date of birth
location: Place of birth
Collection: Milestones (events in the person's timeline/life/history)
Collection: Movies
-------------------------------
Collection: People (famous relatives)
Collection: TriviaFact



Don't over think. Don't panic about doing your planning wrong. You're going to plan wrong, just accept it. I do it after a decade and so does everyone else. You'll learn from every mistake and that will help you not repeat the mistake the next time.

Just try to visualize what kinds of things you're working with and what they really are.

Ok... Next comes a new concept most likely: Database
This might get a little thick if you've never dealt with databases. The goal here is not to teach you all about DBs, but just to introduce them enough so you can understand why they are a good thing and how they can make your life easy if you plan them out well.
Just because a movie object has a property of "title" and a list of actors does not mean you are going to store all that data in literal form in every movie.

We are not going to develop your entire database right now. Just recognize that in the real world of development you store data in a database. Databases are tables of data where horizontal rows are records and columns are the fields.

Person table
---------------------------------------------
ID   |NameFirst   |  NameLast | DOB       | PlaceOfBirth       |
001  |Clint       | tlhIntoq  | 05may2330 | Klingon Home World |
002  |Worf        | Mogh      | 01jul2315 | Mining moon        |

Notice that this table does not track if the person is an actor or a director. Well why not? Because its hard to say if this person is just an actor or a brilliant actor, director, writer, producer, music score writer all in one.

Job table
----------------------------
ID   |  Name
001  |  Actor
002  |  Director


PersonToJob table
------------------------------
PersonID | JobID
123 | 001
123 | 002
15 | 043

We have just related actor 001 to being both an actor and a director. Person 15 is only related to being a set carpenter. If 5 years from now that carpenter also becomes a stunt man you just add one row in the PersonToJob table.



Planning....
You don't want to store all the data of every movie inside every actor, do you? What happens when you have to fix a mistake in the movie? You have to go back and update every actor and crewmember. Not to mention that is a LOT of duplicate data to store and keep syncronized. So what do we do about it? We don't store the entire actor record inside the movie record. We just store a REFERENCE to the actor

Movie table
--------------------------------------------
ID   |  Title
001  | Stripes
002  | Night of the living dead
003  | A few good women


Genre table
------------------------------------------------
ID   |  Name
001  |  Sci-fi
002  |  Fantasy
003  |  Action
004  |  Mystery


MovieToActor table
MovieID    | Actor ID
001        | 125
001        | 003
014        | 016
//You add an actor to the movie by adding a row
001        | 119


MovieToGenre table
----------------------------
MovieID    | Genre ID
001        | 003
001        | 015
//See how you can add a genre to the movie by just adding one row in this table?


So what does this look like when you load a Movie object?
MovieID: 001
ActorCollection: 125, 003
and so on


When you update movie 003 to correct the spelling from "Ex-men" to "X-Men" you don't have to update any of the related records. They don't store the string, they just store the movie ID which isn't changing.

When it comes time to display this record you will pull from the database just the information you need for a particular screen/display/window. If you're just looking at a summary of the movie you may not need to pull all the crew names and trivia records.

The concept to recognize the most in all the DB stuff is the same separation of responsibilities that we talked about with your code. The movie object does not try to store all the details of all the actors. The actor object contains its data but does not references back to the movies because it doesn't need to; The MovieToActor table makes that relationship.

What this really means is that your program is not storing any data until it needs it. There are NO movie objects and NO actor objects until you load some based on a query. That means a PC with only 1gig of free ram can still cope with 2 million movies and 10 million actors if it needs to by just loading the data it needs for one screen at a time (called 'paging'). If you just need a page of movie titles you don't load all the other data.

When you query the database for all the action movies, what happens?
  • First we get the ID of the action genre.
  • Then we get a list of all the movie ID's from the MovieToGenre table.
  • Then we loop through that list to get the details for each matching table: Movie table, MovieToActor, MovieToTrivia
  • Once we have a list of all the actor IDs we can get the details we need for this screen: Actor name

This post has been edited by tlhIn`toq: 19 February 2015 - 07:36 AM

Was This Post Helpful? 3
  • +
  • -

#21 Premier2k  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 200
  • Joined: 26-August 08

Re: Throw away a request if any of the IF statements are false

Posted 24 February 2015 - 01:39 AM

tlhIn`toq,

I want to thank you for the help you've provided here. I'm working through your tutorials, and running them over in my head a couple of times. The most useful ones so far are the Separating Data from the GUI and the class one. I'm going to skip using events and delegates yet, I'm trying to run a marathon before I can walk to the end of my road. I need to fully understand the art of separation of concern first.

Your posts (and tutorials) have really opened my eyes to what I'm doing wrong. Going to attempt to make this better and even include a DB with it. I'm familiar with databases in my job anyway and know how they are constructed but it was still useful to read your last post.
I was avoiding the use of databases as I was trying to focus solely on getting the code right, but I'm thinking maybe I need to look at the bigger picture and plan ahead.

If I get stuck I'm sure I'll be back!

As a side note, a question for yourself or any of the moderators, if I do get stuck and return for some advice, should I continue this thread or start a new one that would be more relevant to the question I'll have?

Keep up the fantastic work you do here, I don't think a lot of people remember that you do this out of the kindness of your hearts and not for any monetary gain.

Premier2k

This post has been edited by Premier2k: 24 February 2015 - 02:42 AM

Was This Post Helpful? 1
  • +
  • -

#22 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6505
  • View blog
  • Posts: 14,360
  • Joined: 02-June 10

Re: Throw away a request if any of the IF statements are false

Posted 24 February 2015 - 05:38 AM

Thank you very much. I know I'm a bit of a hard ass at times and I hear that plenty, but its not very often someone takes the time to say 'thanks'. It goes a long way to reassure that not all rookies are lazy. <laugh>

As for continuing new questions in the same thread... I'd say it depends on how long its been and how much the new question relates to the original topic. For example I stop notifications on threads after 15-30 days, just because I don't need to be subscribed to 15,000 threads that I've made a comment on. My guess is that after you write versions 2 & 3 of this program (learning from each re-start) your next questions will be different enough where a new thread will just make sense.

Keep up the hard work and effort. I know it can seem like slow-going at times but there is no magic bullet. If its any consolation even those of use with more than a decade are still doing the same thing: Putting in long hours after the job to learn new techniques, new technologies, new patterns and models. But learning is exponential. Once you know 2 things the 3rd is easier. When you have 10 concepts under your belt the 11th is like "Oh, that's similar to blah blah". At the 40th concept you read about you're thinking, "Hey, that's like this other concept but cleaner because of wonk wonk. I like it." Its all about momentum: Once you get the educational ball rolling you can keep it going with just a little push here and there.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2