|
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.
|
# ? Feb 21, 2012 22:15 |
|
|
# ? May 16, 2024 09:50 |
|
JawnV6 posted:It's taking the first 16 bits. Not 2^16 or 65,536. Yeah you're right. Was trying to convey 16 bits of data in both.
|
# ? Feb 21, 2012 22:28 |
|
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'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).
|
# ? Feb 21, 2012 22:37 |
|
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: 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.
|
# ? Feb 21, 2012 23:10 |
|
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:
E: As it is now, the application simply crashes when a string is entered.
|
# ? Feb 22, 2012 01:08 |
|
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? Well, let's look at the documentation for Scanner.nextInt(). Look at that: Javadocs posted:Throws: 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.
|
# ? Feb 22, 2012 01:14 |
|
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().
|
# ? Feb 22, 2012 01:15 |
|
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 |
# ? Feb 22, 2012 01:17 |
|
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.
|
# ? Feb 22, 2012 01:25 |
|
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"). 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 |
# ? Feb 22, 2012 01:36 |
|
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. 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
|
# ? Feb 22, 2012 02:13 |
|
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.
|
# ? Feb 22, 2012 03:50 |
|
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:
|
# ? Feb 22, 2012 04:35 |
|
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 */
|
# ? Feb 22, 2012 04:36 |
|
csammis posted:You have a semicolon after the while(). Take it out. 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.
|
# ? Feb 22, 2012 04:48 |
|
csammis posted:You have a semicolon after the while(). Take it out. 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:
Tots fucked around with this message at 05:03 on Feb 22, 2012 |
# ? Feb 22, 2012 04:59 |
|
Tots posted:gently caress me. 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.
|
# ? Feb 22, 2012 05:00 |
|
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.
|
# ? Feb 22, 2012 05:02 |
|
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.
|
# ? Feb 22, 2012 05:07 |
|
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:
|
# ? Feb 22, 2012 05:11 |
|
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.
|
# ? Feb 22, 2012 05:14 |
|
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. 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. No, seriously, that's the reasoning they give here.
|
# ? Feb 22, 2012 05:14 |
|
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.
|
# ? Feb 22, 2012 05:22 |
|
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.
|
# ? Feb 22, 2012 05:22 |
|
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.
|
# ? Feb 22, 2012 05:25 |
|
^^ 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.
|
# ? Feb 22, 2012 05:28 |
|
ToxicFrog posted:Back to the documentation we go: 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:
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 |
# ? Feb 22, 2012 05:30 |
|
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:
I would much rather sacrifice static typing for easier to understand and use syntax when teaching CS101 or whatever. Seriously, how does this: code:
code:
Look Around You fucked around with this message at 05:41 on Feb 22, 2012 |
# ? Feb 22, 2012 05:32 |
|
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?
|
# ? Feb 22, 2012 05:34 |
|
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.
|
# ? Feb 22, 2012 05:36 |
|
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.)
|
# ? Feb 22, 2012 05:54 |
|
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.
|
# ? Feb 22, 2012 06:03 |
|
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.
|
# ? Feb 22, 2012 06:06 |
|
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 |
# ? Feb 22, 2012 06:07 |
|
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? 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 |
# ? Feb 22, 2012 06:12 |
|
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.
|
# ? Feb 22, 2012 06:20 |
|
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:
Tots fucked around with this message at 06:26 on Feb 22, 2012 |
# ? Feb 22, 2012 06:24 |
|
Tots posted:Alright, I'm probably wearing out my welcome, but the cogs are turning. 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).
|
# ? Feb 22, 2012 06:32 |
|
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.
|
# ? Feb 22, 2012 06:47 |
|
|
# ? May 16, 2024 09:50 |
|
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?
|
# ? Feb 22, 2012 06:49 |