Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
ultrafilter
Aug 23, 2007

It's okay if you have any questions.


Munkeymon posted:

Yeah, it is probably paranoia, and I'm trying to say that you should do 10k 'dice rolls' and see if the distribution of that is skewed because 5-10 isn't enough of a sample to determine whether something is actually wrong. One test method could do that for you and give you more (or even less) confidence in your results.

You need to look at more than just the distribution of values, or you'll accept something that's not random at all. The standard procedures are known as the diehard tests, and there are various implementations available. Any prng that passes those looks pretty random.

Adbot
ADBOT LOVES YOU

Strong Sauce
Jul 2, 2003

You know I am not really your father.





JawnV6 posted:

It's taking the first 16 bits. Not 2^16 or 65,536.

0xf = 0b1111 = 15

Not 16.

Yeah you're right. Was trying to convey 16 bits of data in both.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

ufarn posted:

I am currently building a static blog hosted on Amazon S3, and this requires using a subdomain to point to the S3 bucket - in other words that I host the site on https://www.mydomain.com. Now, it's not like I can just turn away my non-www visitors, so which is the best way to redirect them?

I don't know a whole lot about the SEO stuff that goes on behind the scenes, and I obviously don't want to cripple the traffic of my blog, so which is the smoothest way to go about it?

I'm not sure what you're asking here; you have a 'real' site somewhere at www and the blog site at amazon? You can set up your DNS so that:
- blog.mydomain.com goes to S3
- https://www.mydomain.com goes to your normal site

If you don't have control over the DNS you can do a 301 redirect using .htaccess/IIS, but be careful. It probably should be permanent if you're worried about SEO (e.g. don't undo the 301 a week later; google hates temporary 301s).

ufarn
May 30, 2009

Scaramouche posted:

I'm not sure what you're asking here; you have a 'real' site somewhere at www and the blog site at amazon? You can set up your DNS so that:
- blog.mydomain.com goes to S3
- https://www.mydomain.com goes to your normal site

If you don't have control over the DNS you can do a 301 redirect using .htaccess/IIS, but be careful. It probably should be permanent if you're worried about SEO (e.g. don't undo the 301 a week later; google hates temporary 301s).
I have DNS access, so I am mucking around with CNAMEs, although I don't know if Name.com support wildcards for subdomains.

I have one for all the domain - including subdomains. In other words, the blog is the site, and the site is the blog. I just need the canonical site to be https://www.mysite.com because S3 requires a subdomain that points to the bucket.

Tots
Sep 3, 2007

:frogout:
In Java I have a switch statement depending on a variable declared as int. I collect the value to apply to the switch statement using the scanner class. How can I return an error if the user inputs a string?

IE

code:
Scanner switchScan = new Scanner(System.in);
System.out.println("Pick a number 1-4");
int switchVariable = switchScan.nextInt();


switch (switchVariable){
     case 1:
          System.out.println("It's 1");
          break;
     case 2:
          System.out.println("It's 2");
          break;
     case 3:
          System.out.println("It's 3");
          break;
     case 4:
          System.out.println("It's 4");
          break;
     default:
          System.out.println("Please pick a number 1-4");
          int switchVariable = switchScan.nextInt();
          break;
}
In other words, I want what happens in case default to happen if they enter a character or a string in addition to a number outside of the 1-4 scope.

E: As it is now, the application simply crashes when a string is entered.

ToxicFrog
Apr 26, 2008


Tots posted:

In Java I have a switch statement depending on a variable declared as int. I collect the value to apply to the switch statement using the scanner class. How can I return an error if the user inputs a string?

In other words, I want what happens in case default to happen if they enter a character or a string in addition to a number outside of the 1-4 scope.

E: As it is now, the application simply crashes when a string is entered.

Well, let's look at the documentation for Scanner.nextInt().

Look at that:

Javadocs posted:

Throws:
InputMismatchException - if the next token does not match the Integer regular expression, or is out of range

Of course, you'd also know this if you looked at the crash, since it says right there that it crashed due to an unhandled InputMismatchException.

So, catch the exception thrown by nextInt() using a try-catch block as normal and react to it appropriately.

pseudorandom name
May 6, 2007

If you read the Scanner.nextInt() documentation, you'd see that it throws an InputMismatchException if the next token isn't an integer.

Alternately, use Scanner.hasNextInt().

Tots
Sep 3, 2007

:frogout:
Oh, awesome. Still new to the game and I didn't think of looking at the documentation, which in hindsight should have been my obvious first resource. Thanks.

Tots fucked around with this message at 01:24 on Feb 22, 2012

ToxicFrog
Apr 26, 2008


Tots posted:

Oh, awesome. Still new to the game, and I didn't think of looking at the documentation, which in hindsight should have been my obvious first resource. Thanks.

This is not true of all languages or libraries, but the Java documentation is actually quite good if you already know what you're looking for (ie "how do I use class X").

It's less good for answering questions like "what classes do I need to solve problem Y", since for any given task, there's one class in the JRE that's poorly suited for it, and another half dozen that are very unsuited for it but can be made to work with some suffering, and it's a crapshoot which one you find first.

Tots
Sep 3, 2007

:frogout:

ToxicFrog posted:

This is not true of all languages or libraries, but the Java documentation is actually quite good if you already know what you're looking for (ie "how do I use class X").

It's less good for answering questions like "what classes do I need to solve problem Y", since for any given task, there's one class in the JRE that's poorly suited for it, and another half dozen that are very unsuited for it but can be made to work with some suffering, and it's a crapshoot which one you find first.

Is there a recommended go to resource around here for explaining Java related things at a very rudimentary level? For instance, I have never used a try-catch block before. Instead of just googling and blindclicking links I'd like a go-to resource that I know is thorough and easy to digest.

E: Actually, the oracle.com tutorials (which was the first google result) looks pretty good. I'm still open to suggestions though.
http://docs.oracle.com/javase/tutorial/essential/exceptions/try.html

Tots fucked around with this message at 01:42 on Feb 22, 2012

ToxicFrog
Apr 26, 2008


Tots posted:

Is there a recommended go to resource around here for explaining Java related things at a very rudimentary level? For instance, I have never used a try-catch block before. Instead of just googling and blindclicking links I'd like a go-to resource that I know is thorough and easy to digest.

E: Actually, the oracle.com tutorials (which was the first google result) looks pretty good. I'm still open to suggestions though.
http://docs.oracle.com/javase/tutorial/essential/exceptions/try.html

There is a Java questions that don't deserve their own thread thread, which might have some good recommendations.

Sorry I can't be more helpful, but I haven't used Java for years now. thank god

Look Around You
Jan 19, 2009

Java in a Nutshell is pretty good. It's a little dated; it's written for Java 1.5 (or java 5 whatever the hell they're calling it), but I honestly can't think of all that many really significant changes between Java 1.5 and Java 7.

Tots
Sep 3, 2007

:frogout:
Holy christ is this frustrating. I don't even actually need to do this for the assignment, but I got curious and now I loving hate that I can't make it work.

Why does this just give me a blank screen instead of prompting for input?

It starts out with tryAgain == true, so then it should run the code inside the try block. Right? RIGHT?! gently caress.

code:
public static void main(String[] args) {
        EmployeePayment empPayment = new EmployeePayment();
        double managerPay = empPayment.setManagerPay(625.00);
        Scanner scan = new Scanner(System.in); 
        boolean tryAgain = true;
        
            while (tryAgain == true);
            {
				try{
					System.out.println("Please enter a paycode or -1 to exit");
					int payCode = scan.nextInt();


						while (payCode != -1)
						{

							switch (payCode){
								case 1:
									System.out.println("Manager Selected.");
									System.out.println("Manager's pay is: $" + 
											empPayment.calcManagerPay());
									System.out.println("Enter paycode (-1 to end):");                           
									payCode = scan.nextInt();
									empPayment.addEmployee(1);
									break;
								case 2:
									Scanner rateScan = new Scanner(System.in);
									Scanner hourScan = new Scanner(System.in);
									System.out.println("Hourly Worker Selected. ");
									System.out.println("What is the worker's hourly rate? ");
									double rate = rateScan.nextDouble();
									System.out.println("How many hours did they work? ");
									double hours = hourScan.nextDouble();
									System.out.println("Hourly worker's pay is: $" + 
											empPayment.calcHourlyWorkerPay(rate, hours));
									System.out.println("Enter paycode (-1 to end):");                           
									payCode = scan.nextInt();
									empPayment.addEmployee(2);
									break;
								case 3:
									Scanner salesScan = new Scanner(System.in);
									System.out.println("Commission Worker Selected. ");
									System.out.println("What was the commission worker's gross "
											+ "sales? ");
									double sales = salesScan.nextDouble();
									System.out.println("Commission worker's pay is: $" + 
											empPayment.calcCommWorkerPay(sales));
									System.out.println("Enter paycode (-1 to end):");                           
									payCode = scan.nextInt();
									empPayment.addEmployee(3);
									break;
								case 4:
									Scanner scanPieces = new Scanner(System.in);
									Scanner scanWage = new Scanner(System.in);
									System.out.println("Piece worker Selected." );
									System.out.println("How many pieces did the worker sell?");
									double pieces = scanPieces.nextDouble();                    
									System.out.println("What is the wage per piece?");
									double wage = scanWage.nextDouble();
									System.out.println("Piece worker's pay is: $" + 
											empPayment.calcPieceWorkerPay(pieces, wage));
									System.out.println("Enter paycode (-1 to end):");                           
									payCode = scan.nextInt();
									empPayment.addEmployee(4);
									break;

								default:
									System.out.println("Please enter a valid paycode or -1 to"
											+ " exit");
									payCode = scan.nextInt();
									break;
							}
						tryAgain = false;
						}
					}
				catch(InputMismatchException e){
					System.out.println("Invalid entry");
					return;
            }
        System.out.println("Number of managers paid: " + empPayment.numManager);
        System.out.println("Number of hourly workers paid: " + empPayment.numHourlyWorker);
        System.out.println("Number of commission workers paid: " + empPayment.numCommWorker);
        System.out.println("Number of piece workers paid: " + empPayment.numPieceWorker);






            }
    }
}

csammis
Aug 26, 2003

Mental Institution
You have a semicolon after the while(). Take it out.

e: a little more explanation: that line is effectively while (tryAgain == true) /* empty statement that is executed forever */ ; /* the rest of your code */

Look Around You
Jan 19, 2009

csammis posted:

You have a semicolon after the while(). Take it out.

e: a little more explanation: that line is effectively while (tryAgain == true) /* empty statement that is executed forever */ ; /* the rest of your code */

Why the gently caress do schools teach java anyway holy hell.

e:
I mean this is stuff you have to learn about eventually, but I would argue that intro CS courses should focus on concepts and not arcane rear end syntax, but I guess that's for another thread.

Tots
Sep 3, 2007

:frogout:

csammis posted:

You have a semicolon after the while(). Take it out.

e: a little more explanation: that line is effectively while (tryAgain == true) /* empty statement that is executed forever */ ; /* the rest of your code */

gently caress me.

Okay, so it works, but it looks like after it gets an error it just exits with my error message. What I was going for is to have it continue running from the beginning of while (tryAgain = true) after it catches the error. That was the whole reason I stuck that while statement in there.

E: I put together code for testing purposes for what I want to accomplish. Should be easier to see what's going on and what I want

code:
public class JavaApplication2 {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        boolean tryAgain = true;
        int switchVariable;
        
        while (tryAgain == true){
            try{
            
            System.out.println("Enter a number");
            switchVariable = scan.nextInt();

                while (switchVariable != 0){

                    switch (switchVariable)
                    {
                        case 1:
                            System.out.println("Case 1");
                            switchVariable = scan.nextInt();
                                    break;
                        case 2:
                            System.out.println("Case 2");
                            switchVariable = scan.nextInt();
                                    break;
                        default:
                            System.out.println("Not a valid number");
                            switchVariable = scan.nextInt();
                    }
                }
                tryAgain = false;
            }
            catch(InputMismatchException e){
                System.out.println("Not an integer");
                tryAgain = true;
                break;
                //I WANT THIS TO RUN AGAIN FROM while (tryAgain == true) AFTER IT CATCHES THE ERROR.  Is this possible?
            }
            }
        System.out.println("Program Finished");
        }
    }

Tots fucked around with this message at 05:03 on Feb 22, 2012

Look Around You
Jan 19, 2009

Tots posted:

gently caress me.

Okay, so it works, but it looks like after it gets an error it just exits with my error message. What I was going for is to have it continue running from the beginning of while (tryAgain = true) after it catches the error. That was the whole reason I stuck that while statement in there.

You're gonna have to take the return; out of the catch block then; return leaves the entire function, not just the catch block that you're in.

Tots
Sep 3, 2007

:frogout:

Look Around You posted:

You're gonna have to take the return; out of the catch block then; return leaves the entire function, not just the catch block that you're in.

When I don't put anything in there it repeats the error message ad infinitum.

Look Around You
Jan 19, 2009

Tots posted:

When I don't put anything in there it repeats the error message ad infinitum.

What error message is printing all the time? As an aside, that code is not really structured the best way... you don't really need the inner while loop. Try replacing it with an if statement or just using the switch statement. You almost certainly don't want nested loops here.

Tots
Sep 3, 2007

:frogout:

Look Around You posted:

What error message is printing all the time? As an aside, that code is not really structured the best way... you don't really need the inner while loop. Try replacing it with an if statement or just using the switch statement. You almost certainly don't want nested loops here.

Actually I was wrong. The output when a string is entered is this:

code:
Not an integer
Enter a number
Not an integer
Enter a number
Not an integer
Enter a number
Not an integer
Enter a number
..ad infinitum
So it looks like it does continue to the beginning of the loop, then uses the old input to throw an error again before allowing for new input. Gonna try assigning the switchVariable to an arbitrary int at the end of the catch statement and see what happens.

pseudorandom name
May 6, 2007

quote:

When a scanner throws an InputMismatchException, the scanner will not pass the token that caused the exception, so that it may be retrieved or skipped via some other method.

ToxicFrog
Apr 26, 2008


Tots posted:

When I don't put anything in there it repeats the error message ad infinitum.

Back to the documentation we go:

quote:

When a scanner throws an InputMismatchException, the scanner will not pass the token that caused the exception, so that it may be retrieved or skipped via some other method.

In your exception handler, you need to read and discard the bad token (using, say, nextLine()), or it'll get stuck trying to read the same thing over and over again.

Also, breaking your code down into multiple smaller functions - say, break "read an int" into its own function that loops until the user enters a valid int, and does the exception handling in there - would make this a lot more readable. (So would using continue to make the try block a lot smaller, for that matter, if java lets you do that.)

Look Around You posted:

Why the gently caress do schools teach java anyway holy hell.

e:
I mean this is stuff you have to learn about eventually, but I would argue that intro CS courses should focus on concepts and not arcane rear end syntax, but I guess that's for another thread.

Because otherwise the students in the co-op program will be unhireable (it's not like anyone actually uses Python in the real world, right?), and we don't have the budget to make C and Java addon courses for the co-op students rather making them the introductory courses for everyone. :pseudo:

No, seriously, that's the reasoning they give here.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





I think these two articles written explain good reasons not to learn just Java/C++

http://michaelochurch.wordpress.com/2012/01/24/how-any-software-company-can-cross-the-developer-divide/
http://michaelochurch.wordpress.com/2012/02/14/why-you-cant-hire-good-java-developers/

TL;DR: Because developers who program in obscure high level languages actually love to program, Java is too verbose and too difficult to differentiate between bad and good code in a coding interview...


He makes some good points... people in general aren't going to learn Haskell unless they actually want to.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Python has just as many what-the-gently caress design decisions as Java, and at least Java introduces programmers to rudimentary notions of a type system. There is no truly "appropriate" language for introductory programming courses. At the end of the day they're going to have to learn to think, and that's harder for some people than any syntax you could throw at them.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

ToxicFrog posted:

Because otherwise the students in the co-op program will be unhireable (it's not like anyone actually uses Python in the real world, right?), and we don't have the budget to make C and Java addon courses for the co-op students rather making them the introductory courses for everyone. :pseudo:

No, seriously, that's the reasoning they give here.
I've actually seen co-op hirability used as an argument for teaching Scheme in the intro classes - the logic being that they'd had 100% placement for a few years, so the school should be focusing on getting the students good jobs rather than any job at all, and companies that like to see Scheme on a resume are probably better places to work.

ToxicFrog
Apr 26, 2008


^^ If only they used the same line of thinking here.

Internet Janitor posted:

Python has just as many what-the-gently caress design decisions as Java, and at least Java introduces programmers to rudimentary notions of a type system. There is no truly "appropriate" language for introductory programming courses. At the end of the day they're going to have to learn to think, and that's harder for some people than any syntax you could throw at them.

Yeah, and Python wouldn't be my first choice either. I'd still consider it a much better choice than Java, though - the REPL makes it a lot easier to experiment with, there's much less boilerplate (and thus less risk of cargo cult programming), and the language gets in the way a lot less when you're trying to teach concepts like functional abstraction or recursion.

Tots
Sep 3, 2007

:frogout:

ToxicFrog posted:

Back to the documentation we go:


In your exception handler, you need to read and discard the bad token (using, say, nextLine()), or it'll get stuck trying to read the same thing over and over again.


Thanks a lot for your help. Most of my problem at this point is just lack of exposure I think. This is literally my 1st java assignment that isn't just changing very basic code that's already written for me. Even though the docs are extremely helpful, "When a scanner throws an InputMismatchException, the scanner will not pass the token that caused the exception, so that it may be retrieved or skipped via some other method." doesn't mean very much to me at this point.

E: When I put my brain to breaking it down it begins to make sense, but the concepts aren't really internalized at this point. It didn't register as 'important' to me until someone else explained why it's important.

quote:


Also, breaking your code down into multiple smaller functions - say, break "read an int" into its own function that loops until the user enters a valid int, and does the exception handling in there - would make this a lot more readable. (So would using continue to make the try block a lot smaller, for that matter, if java lets you do that.)

Taking it one step at a time, but I will consider this. Thanks.


Just to reaffirm what I am doing here (I got it to work just by adding in a nextLine() statement at the end of the catch), the exception handler is just going to keep reading that bad input until another method tells it to do something else with it. Is that correct? So the catch statement finishes, then returns to the beginning of the loop using whatever the most recent input was unless I specify that it should skip that input, or otherwise do something with it.

Tots fucked around with this message at 05:33 on Feb 22, 2012

Look Around You
Jan 19, 2009

Internet Janitor posted:

Python has just as many what-the-gently caress design decisions as Java, and at least Java introduces programmers to rudimentary notions of a type system. There is no truly "appropriate" language for introductory programming courses. At the end of the day they're going to have to learn to think, and that's harder for some people than any syntax you could throw at them.

Python may have some odd syntax, but seriously if you're learning what a loop is and how to write a program, this:

code:
public class MyDumbJavaApp {
  public static void main(String[] args) {

  }
}
all looks like magic words, and there's no way to adequately explain them without delving into a lot deeper concepts.

I would much rather sacrifice static typing for easier to understand and use syntax when teaching CS101 or whatever.

Seriously, how does this:
code:
public class MyLoopProgram {
  public static void main(String[] args) {
    int input;
    Scanner in = new Scanner(System.in);
    
    input = in.nextInt();

    while (input != -1) {
        System.out.println(input);
        input = in.nextInt();
    }
    System.out.println("Done!");
  }
}
teach concepts better than this:
code:
x = int(raw_input())
while x != -1:
    print(x)
    x = int(raw_input())
print("done!")
edit: I just realized I had a missing semicolon error in my java example :lol:

Look Around You fucked around with this message at 05:41 on Feb 22, 2012

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Internet Janitor posted:

Python has just as many what-the-gently caress design decisions as Java and at least Java introduces programmers to rudimentary notions of a type system.

I don't get it. Are you saying that Python has no type system? That Java's is rudimentary? Or that Java's type system is somehow preferable to Python's in an introductory setting? Keep in mind we're talking about people writing their very first lines of code.

quote:

There is no truly "appropriate" language for introductory programming courses. At the end of the day they're going to have to learn to think, and that's harder for some people than any syntax you could throw at them.

Yet you've already ranked two languages in order of desirability for an introductory programming class. Why stop there?

Look Around You
Jan 19, 2009

Tots posted:

Just to reaffirm what I am doing here (I got it to work just by adding in a nextLine() statement at the end of the catch), the exception handler is just going to keep reading that bad input until another method tells it to do something else with it. Is that correct? So the catch statement finishes, then returns to the beginning of the loop using whatever the most recent input was unless I specify that it should skip that input, or otherwise do something with it.

Not exactly; the exception handler isn't doing anything in your old version, it just prints "hey this was bad" and swallows the error and goes back to the top of the loop. The switchVariable = scan.nextInt() will keep trying to read the old input as a number, which throws that exception, which goes back to your exception handler, forever. The scan.nextLine() will throw away this garbage input and then the next call to scan.nextInt() will actually ask the user for new input again.

ToxicFrog
Apr 26, 2008


Tots posted:

E: When I put my brain to breaking it down it begins to make sense, but the concepts aren't really internalized at this point. It didn't register as 'important' to me until someone else explained why it's important.

That will come with time and practice, although (see concurrent conversation in this thread) Java has enough overhead (both in "amount of code needed" and "amount of stuff to be aware of") that it makes a pretty bad first language, and encourages occurences like this.

quote:

Taking it one step at a time, but I will consider this. Thanks.

Maybe I've just been reading Structure and Interpretation too much, but it seems that functional abstraction and how to break down your program into smaller, easy to reason about chunks thereby should be the first step after super-basic things like "what is a program". (This is a bitch about the course, not you.)

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
pokeyman: I was mainly reacting to the assertion that Java syntax is onerously arcane and confusing. What would you consider a good language for beginning programmers?

ToxicFrog: At the risk of being a broken record, there is a language where breaking things into procedures is more or less universally the first step in teaching the language, long before variables, loops or conditionals. It also has a REPL. I'm not sure how inviting it would be to a new programmer.

ToxicFrog
Apr 26, 2008


Internet Janitor posted:

ToxicFrog: At the risk of being a broken record, there is a language where breaking things into procedures is more or less universally the first step in teaching the language, long before variables, loops or conditionals. It also has a REPL. I'm not sure how inviting it would be to a new programmer.

I'm not sure either, honestly. I do like Forth and Forthy languages, though. I should implement one someday. :)

My personal pick would be Scheme or a variant thereof, but as I've mentioned before Structure and Interpretation of Computer Programs had a significant influence on me. Lua might work well as well, it has a lot of lisp-inspired features and is easy to play with but has a "friendlier" superficial appearance and simple syntax.

Tots
Sep 3, 2007

:frogout:

ToxicFrog posted:

Maybe I've just been reading Structure and Interpretation too much, but it seems that functional abstraction and how to break down your program into smaller, easy to reason about chunks thereby should be the first step after super-basic things like "what is a program". (This is a bitch about the course, not you.)

I'm going to try to stick input collecting and error reporting in its own method tomorrow after I've gotten some sleep. Expect me back in this thread.

E: How long until I am not retarded at programming?

Tots fucked around with this message at 06:10 on Feb 22, 2012

Look Around You
Jan 19, 2009

Internet Janitor posted:

pokeyman: I was mainly reacting to the assertion that Java syntax is onerously arcane and confusing. What would you consider a good language for beginning programmers?

ToxicFrog: At the risk of being a broken record, there is a language where breaking things into procedures is more or less universally the first step in teaching the language, long before variables, loops or conditionals. It also has a REPL. I'm not sure how inviting it would be to a new programmer.

THere's a ton of languages that focus on breaking things into procedures that are probably less arcane than FORTH, if only for the fact that you're not managing a stack in them.

Scheme is a pretty great beginning language (and we have a thread for it too!). It's simple, expressive and has an extremely consistent syntax. Plus it heavily encourages breaking things up into functions since, well, it's a functional language.

The drawback with this though is that scheme (and lisp in general) is not really widely used, and it's not really accessible or readable to people who haven't ever seen the source for a program in their lives, which is why I think python is a lot better for this sort of thing.

e:

tots posted:

E: How long until I am not retarded at programming?

It takes a while to get used to. All of us started out at some point.

It also depends on how much effort you put in and how much you look up and learn outside of class. If you just do what you need to in class and only learn java then you're going to miss out on a lot of pretty important stuff. You'll become a decent code monkey, but that doesn't mean you're a good programmer. A couple good books to read through are How to Design Programs and The Structure and Interpretation of Computer Programs (aka SICP or the wizard book). They're both available for free online and they're both really great reads. They don't use java, instead they use racket, a dialect of scheme (which is a dialect of lisp!). If you go through them, I'd suggest going through HtDP first, it's a bit more accessible. There's also full video of the 1986 MIT intro to CS course which uses SICP as it's text... despite it's age it's actually still extremely relevant.

Look Around You fucked around with this message at 06:20 on Feb 22, 2012

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Look Around You posted:

The drawback with this though is that scheme (and lisp in general) is not really widely used, and it's not really accessible or readable to people who haven't ever seen the source for a program in their lives, which is why I think python is a lot better for this sort of thing.

I don't think anything is, although there are varying degrees of unreadability and bewilderment. I think that python would make a reasonably good first programming language for non-CS majors, and a poor one for CS and related majors.

Tots
Sep 3, 2007

:frogout:
Alright, I'm probably wearing out my welcome, but the cogs are turning.

If I wanted to abstract the input and error handling, would this be the right track?

code:
main{

 Prompt: Enter a Pay Code

 Call a method that takes payCode input and validates it.

 payCode = mainclass.PayCodeHandler();

 Switch statement based on payCode{

	Cases 1-4 for each valid paycode
	Case 99 for any invalid payCode
 }
}

public int PayCodeHandler(){
try
	collect input
	if 1-4 return 1-4
	else return 99
catch
Error?  return 99

Tots fucked around with this message at 06:26 on Feb 22, 2012

Look Around You
Jan 19, 2009

Tots posted:

Alright, I'm probably wearing out my welcome, but the cogs are turning.

If I wanted to abstract the input and error handling, would this be the right track?

code:
main{

 Prompt: Enter a Pay Code

 Call a method that takes payCode input and validates it.

 payCode = mainclass.PayCodeHandler();

 Switch statement based on payCode{

	Cases 1-4 for each valid paycode
	Case 99 for any invalid payCode
 }
}

public int PayCodeHandler(){
try
	collect input
	if 1-4 return 1-4
	else return 99
catch
Error?  return 99

This looks pretty good. Are you sure you want to return '99' on an InputMismatchException and not display an error, discard the invalid input and get a new input? This is more up to you, but if you return 99 on invalid input (strings etc) then your program will end after you do that. There's more ways to break it up even further too. If you find yourself typing the same thing over and over again (or at least extremely similar things), see if there's a way to make it into it's own function (or method or whatever the hell you want to call them).

Tots
Sep 3, 2007

:frogout:

Look Around You posted:

This looks pretty good. Are you sure you want to return '99' on an InputMismatchException and not display an error, discard the invalid input and get a new input? This is more up to you, but if you return 99 on invalid input (strings etc) then your program will end after you do that. There's more ways to break it up even further too. If you find yourself typing the same thing over and over again (or at least extremely similar things), see if there's a way to make it into it's own function (or method or whatever the hell you want to call them).

Well the plan was to print a generic error message in Case 99. I was under the impression that the method would end resulting in the method returning to main with a value of 99 (or 1-4 if it's valid). Then I would call the method again at the end of each case.

Adbot
ADBOT LOVES YOU

Look Around You
Jan 19, 2009

Tots posted:

Well the plan was to print a generic error message in Case 99. I was under the impression that the method would end resulting in the method returning to main with a value of 99 (or 1-4 if it's valid). Then I would call the method again at the end of each case.

Well, why not pull the method out of the switch statement so that you're only using it at one point? Also, if you print a generic error on 99 and return it, when will your program halt? Is there another specific code to terminate?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply