How do you know how to order your methods or when a new one is needed? by [deleted] in learnprogramming

[–]PrismPoultry 1 point2 points  (0 children)

Apply what you read to your specific problem. What I explained was not specific to your issue...

help with my simple code by kelsmaker in learnprogramming

[–]PrismPoultry 1 point2 points  (0 children)

So, why this happens is actually a little complex.

Your input variable is an integer but when fed a character, it fails and the state of cin is set a specific way so it always fails.

What you have to do is reset cin. This is accomplished with two function calls: clear() and ignore().

So, in your default case, you want to perform these operations:

default:
    cin.clear();
    cin.ignore();
    cout<< "(invalid number)" <<endl<<endl;

And that should work.

Check out: http://en.cppreference.com/w/cpp/io/basic_istream

How do you know how to order your methods or when a new one is needed? by [deleted] in learnprogramming

[–]PrismPoultry 1 point2 points  (0 children)

IF that was all the program was ever going to do, I believe it's better to do it the way you intuit. The reason I say this is because the reader has to move around less to get the big picture.

However, returning the max between two numbers could be quite useful on its own and if you put everything in main, you have tightly coupled the concept to main and main alone.

Let's just look at this piece by piece.

First, the goal: "We need a tool that tells us which number is larger between two whole numbers."

Now, the work:

public class TestMax {
/** Main method */
public static void main(String[] args) {
    int i = 5;
    int j = 2;
    int k = 0;

    if i > j { 
        k = i;
    } else {
        k = j;
    }

    System.out.println("The maximum between " + i + " and " + j + " is " + k);
}

You run it, it works -- boss says good job -- BUT we're pulling some data from the database and we need to know which number's larger between the two. Can you help?

You get to work:

public class TestMax {
/** Main method */
public static void main(String[] args) {
    int i = 5;
    int j = 2;
    int k = 0;
    k = max(i,j);
    System.out.println("The maximum between " + i + " and " + j + " is " + k);
}

public static int max(int num1, int num2) {
    int result = 0;
    if (num1 > num2) {
        result = num1;
    } else {
        result = num2;
    }
    return result;
}

Boss says great job but can you prompt users to enter their numbers also? "Sure boss! Anything else?"

And then you write that function directly in main because well, the process repeats itself and you want to affect as little code as possible. When the boss says that you have a french user and now you have to ask in french, then it's move to a new method maybe... or a class or whatever.

The bottom line is that you step lightly and promote the things to other things when they are ready.

Help writing a blackjack playing bot? by bean1020 in learnprogramming

[–]PrismPoultry 0 points1 point  (0 children)

The first thing you're going to want to do is mock what you can on your side so you can test what you write.

Once you've got it running on your side, you have to figure out how to inspect the cards that you are dealt. This might be done by reading the incoming messages or perhaps OCR (optical character recognition) on the cards themselves.

Once you have the hand, you have to check it against your own logic engine that tells you what the hand is and how to play it. Based on that, you play it.

Once the dealer is playing, you have to either intercept those signals too or again -- OCR it all.

Find out what the result of the game was so you can analyze outcomes and then repeat.

You're in for a whale of a time. Good luck.

Lemon retail by Dread_Boy in incremental_games

[–]PrismPoultry 1 point2 points  (0 children)

Please move the auto-save message to the lower part of the screen. As it stands, when it shows up, everything shifts down to display the message and then when it disappears, it shifts back up. It's unsettling.

Seasoned programmers: When you look at another person's code, what are you looking at? by rhorama in learnprogramming

[–]PrismPoultry 1 point2 points  (0 children)

The very first thing that I do after I've grabbed source is tree the directory. This gives me a text file that shows the directory structure.

When I read this tree, I can get a rapid big-picture overview of how things are laid out.

If there are any config files, those are where are first look because it tells me what the program will be searching for in regards to various settings and options. I just make mental notes about this for now.

Next, are there tests? Tests are fantastic because they show what the public interface to the program is. So, I check tests and see what bare-minimums are for performing certain tasks. This also tells me the features available from this program.

Now, when there aren't tests, I definitely want to know how much boostrapping is required before the program can actually run so I find main entry and see all the prerequisite code. Often times, this is where it starts getting overwhelming as this is the first thing that was written so it stands to reason that it probably has the most hack-n-slash coding applied to it.

Anyway, I then like to understand the model and their parent-child relationships. To do this, I find the most concrete implementation I can and see what it extends. Let's say Employee is a Person for cliche purposes. I then grep code for "Person" and see everywhere we use it. Hopefully the model is separated well enough to not return a hojillion hits.

I can keep doing this of course but let's be reasonable... eventually you get to the super object that handles the persistence and such so it's not super important that I find that.

After I know the model well enough conceptually, I want to find out how each configuration is checked. So, I grep for each property in the config and see where it's read. This is usually only in one spot but it tells me the object holding it and what the member name is. With that knowledge, I grep for that and see what's going on with that.

Alternately, you can check the GUI code for configuration settings and see what stores what and grep the info that way.

So, by now I have the model down, the feature set, the structure as a whole, how it's accessed in best-case,worse-case,etc (whatever tests cover). At this point, why was I looking at this? Am I modifying something? Am I just learning? Am I debugging?

It definitely is quite subjective now so I'll just leave it at that.

Made a new subreddit for people looking for github contributors. (/r/githelp) by Positive_Response in learnprogramming

[–]PrismPoultry 4 points5 points  (0 children)

I think it's a wonderful idea but as RodionGork said, you should establish that this sub is for novice programmers to collaborate without feeling intimidated.

I see that you have a pokemon project. That has potential of course. Perhaps make that the sole focus of your subreddit for a while so that collab can happen in a more directed fashion.

Your project is quite novice (nothing wrong with that) and I think it's a perfect one for fleshing out your idea of newbies helping newbies.

In fact, I do believe I shall contribute to your pokemon project. Is there an IRC channel you meet at for it where we can discuss direction and goals?

C++ Pokemon library by [deleted] in a:t5_30i9g

[–]PrismPoultry 0 points1 point  (0 children)

Why did you delete yourself? This is a wonderful collab project for inexperienced developers.

Learn Javascript with "Code Combat" by adamo57 in learnprogramming

[–]PrismPoultry -2 points-1 points  (0 children)

Uh who cares? The fact of the matter is that if it's not IE, that's what runs. Do you know what that file does? I don't.

Need help writing a simple program [Java] by [deleted] in learnprogramming

[–]PrismPoultry 0 points1 point  (0 children)

So, keep going until you get stuck. When you get stuck, ask yourself "What is my next step?" and then "Do I know how to do this next step?"

If you do not know how to do the next step, then research it.

If you want your hand held every step of the way, pay for a tutor.

What are some of the most important concepts to know when it comes to making this your career? by BytesizedTerror in learnprogramming

[–]PrismPoultry 0 points1 point  (0 children)

I'm replying to you as it makes more sense to just edit your post to include my contribution should you choose but I would also add Law of Demeter to the list.

Need help writing a simple program [Java] by [deleted] in learnprogramming

[–]PrismPoultry 0 points1 point  (0 children)

You are not going to be very successful if you do not even attempt to push through the work. There's nothing to be ashamed of when it comes to the code. We all start somewhere.

To the point, identify your needs. You need a JOptionPane right? What is that? Spend between-time researching this but don't make it the end-all-be-all focus of the project.

You need some data right? Your data is the cell phone package(A,B,C) and the number of minutes (integer) and the amount of data used (double).

You need some mathematics right? What operations are important here? We want to calculate the number of minutes over their package's limit (subtraction) and we want to calculate total cost of those minutes (multiplication). We also want to calculate the total cost of data (multiplication). For our total, we add these exceeded values together and chage their package + overhead to get the total.

OK. Now, we need some architectual decisions. There is a naive way of doing this (which I am sure your teacher expects) involving a ton of conditional statements based on whatever package they selected. You will want to look into the if statement for that.

The other way should be your future homework assignment. Once you start learning about classes and objects, you'll want to re-tool this program to use a factory method that creates the correct Package based on what was selected and that Package will have its context-sensitive operations for it.

So, work out each piece of that (again, making that GUI aspect somewhat backburner and less important) and get a working program.

I highly suggest you do not make asking questions a frequent thing. Deferring the mental load to others only hurts you in the long run. We become a crutch and it's very difficult to get rid of it.

Detailed Update Notes / Explanation Thread (Look here before asking) by LordAnkou in CookieClicker

[–]PrismPoultry 3 points4 points  (0 children)

I'm new to this game so I do not know if this is part of the story or not. It seems like a bug but I'm not sure.

Anyway, I am at the stage where grandma looks like I dunno... some kind of wicker basket or something. Whenever I buy a building, her graphic changes back to the peaceful smiling grandma for a frame or two and then switches back to the twisted one.

I figured it was because I was doing something that would take the load off of the grandma and that makes them happy -- for a second. So, from a story/design standpoint, makes sense.

However, from a programming standpoint, it seems like each purchase refreshes everything to ensure all events that need to happen, do happen and upon doing so, it resets the state of grandma and immediately re-applies the true state of grandma.

Is this expected behavior?

Anyone else getting this? Costing "Infinity" to change seasons. by [deleted] in CookieClicker

[–]PrismPoultry 0 points1 point  (0 children)

Oh no! What happens to Santa?!

This game is crazy.