I think that the internet has been for years on the path to creating what is essentially an electronic Necronomicon: A collection of blasphemous unrealities so perverse that to even glimpse at its contents, if but for a moment, is to irrevocably forfeit a portion of your sanity.
Xbox - PearlBlueS0ul, Steam
If you ever need to talk to someone, feel free to message me. Yes, that includes you.
Python seems like it'd be a great introductory language. It has that robust, clean syntax with very helpful error messages that new students really benefit from.
Lua has this as well, but you sort of have to roll your own object-oriented framework. Not that it's difficult; it only requires about 10 lines to define a nice base Object prototype. But that's one more barrier to entry. Python has that support built right into the language.
Either way, I'm glad I started with a language that has closures and first-class functions. Those concepts are way too important and useful to be left until later. My university, for instance, taught the entire curriculum in Java and C/C++; most of my graduating class never wrote a single closure. Even the idea behind Java's anonymous classes was barely covered.
Some shenanigans with my degree audit really screwed me over. Learning Intro to C was how all CS and CompEngineers start out, then they move on to CS1. This part is fine. The CS1 course used C to teach data structures and binary trees. What messed me up was that my degree audit was old, so I ended up taking OOP (java) and CS2 (which assumed you already took Java) simultaneously. Trying to do the coursework was a nightmare but the tests were easy.
Cantido on
3DS Friendcode 5413-1311-3767
0
Options
Monkey Ball WarriorA collection of mediocre hatsSeattle, WARegistered Userregular
I would say that the only problem with Python as a intro to coding language is its unorthodox scoping/code block syntax, i.e. significant white space vs. the almost universal C syntax with curly braces. But that part of python still rubs me the wrong way, even though I otherwise really like it. So this might just be a personal qualm.
"I resent the entire notion of a body as an ante and then raise you a generalized dissatisfaction with physicality itself" -- Tycho
The primary problems with Python at the intro level are the lack of static typing and the fact that it is sometimes difficult to talk about abstraction in design as a result. The good thing is that in a traditional CS1 course you tend to write small programs and emphasize other fundamentals over abstraction, so the problems end up being mitigated by design.
@TwitchTV, @Youtube: master-level zerg ladder/customs, commentary, and random miscellany.
0
Options
Mike Danger"Diane..."a place both wonderful and strangeRegistered Userregular
So, right now in my database I have a Majors table and a Requirements table. The Majors table is mostly for prettyprinting/rendering stuff; the Requirements table has got my scheme for representing degree requirements.
Now, I had been doing stuff through the Majors/Requirements controller, but it seems like those aren't a good fit for what I'm thinking about here:
User goes to site -> User picks major from list -> User selects completed courses -> User sees courses remaining + suggestions for next semester
Before I go zooming off into the distance, my thinking right now is that I should be using the Sessions controller.
User goes to site -> new session
User picks major from list -> result stored in session
User picks completed courses -> results stored in session
Logic performed on selections, results displayed.
Is this right? It just seems like defining actions on the Requirement/Majors controller doesn't seem right (as those would be if I was creating a new/updating an old instance of those).
Also, is there an IRC room for this thread? I feel like I have been clogging things up with dumb ol' Rails questions.
admanbunionize your workplaceSeattle, WARegistered Userregular
edited April 2012
"Dumb" questions are pretty much 90% of what this thread is for.
When a User picks a major is that supposed to be an action that permanently (barring a later remove action) associates that user with that major? If so, you should have a database association between users and majors. A Sessions controller is a good thing to have, but you shouldn't be using it to handle actions involving majors or courses (I'm not 100% sure that's what you were suggesting, but it seemed like it). The Sessions controller should exclusively handle creating/updating/deleting sessions -- i.e. signin/signout.
It sounds to me like what you want is to have a many-to-many relationship between majors and requirements, then you add the embedded resource to your router. Then if your user picked the major with id 3, the route would look like this:
/majors/3/reqs/index
with an edit action for a req with id 5 looking like
After my schooling and after learning a few more languages, I think my choice, for a new programmer, would be to learn both Python and C, in no particular order. That will give you a basis for 95% of what you encounter in the real world.
0
Options
jackalFuck Yes. That is an orderly anal warehouse.Registered Userregular
Try moving your sleeps to before your output. I'm wondering if because the sleeps are at the end of the function if it just lets them pass.
Also I'm wondering if because you're not accessing any variables, the JRE assumes that it's safe to let them both enter at the same time. Edit: nevermind I see the output++ there now.
bowen on
not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
You warm the cockles of my heart Uratonky. If it breaks once, with concurrency, it's likely that it will break consistently.
Also, the output doesn't look wrong to me. You've got a semaphore on output only, meaning you can't have concurrent output. Since the sleeps are random, I think one thread can go twice before the other, no?
Okay yeah you guys are right. I changed that but now I'm getting something even more confusing... Does this mean the threads are entering the method at the exact same time?
I'm sorry. I'm reading through the Oracle Java Certification Study Guide and trying out the example they have in the book, then just tweaking it a bit to try out various outputs.
I'm sorry. I'm reading through the Oracle Java Certification Study Guide and trying out the example they have in the book, then just tweaking it a bit to try out various outputs.
Is the example actually Duck/Wabbit season? Because that would be awesome.
I'm sorry. I'm reading through the Oracle Java Certification Study Guide and trying out the example they have in the book, then just tweaking it a bit to try out various outputs.
Is the example actually Duck/Wabbit season? Because that would be awesome.
Nah that was me. :P I figured that since it'll be repeating it's better than Jamaica and Fiji.
Basically how I think synchronized works is they are in the same method at the same time, but, access to variables is a "block" mode. So when they both read the variable it was 3, then they both went to increment it. Oops looks like the first thread is incrementing, have to wait. Looks like they're done, now it's my turn. Doing it.
Synchronized on a method declaration causes the lock associated with the particular method the object is invoked on to be acquired before executing the method. Static synchronized methods grab the lock associated with the entire class.
In your particular example (the original version), each ThreadingExample instance grabs its own particular lock, so there is no blocking that occurs. And also note that the counter is not shared between the threads because it is non-static which probably defeats the purpose of the exercise. What would work is making the instance variable a static variable instead and then using a synchronized block:
synchronized(count) {
// ...
}
Rather than a method-level synchronized annotation.
Kambing on
@TwitchTV, @Youtube: master-level zerg ladder/customs, commentary, and random miscellany.
I would say that the only problem with Python as a intro to coding language is its unorthodox scoping/code block syntax, i.e. significant white space vs. the almost universal C syntax with curly braces. But that part of python still rubs me the wrong way, even though I otherwise really like it. So this might just be a personal qualm.
Python has a clearly defined blocking structure, its a colon (:) followed by a change in indentation, the block is marked by a change to previous indentation.
It's not that "whitespace is meaningful", or that there are no delimiters, its that the delimiters are differently defined. They're purposefully chosen this way to make the code more readable, as code is read much more often that it's written.
Java isn't terrible for an into class. It can be tricky to install and configure for Windows users and it's far too verbose for trivial tasks. That being said, the foundations of the language (assignments, comparisons, loops, functions, etc) are logical enough to follow. The "just ignore 90% of the code in the 'Hello World' example- I'll tell you about it later" is unfortunate.
no, its exactly those things that make it a bad intro language.
"here, install this ubuntu CD... ok, open a console, type "python" type "print 'hello world'" is far simpler to understand.
No, python is my choice. The class is a stipped-down version of my traditional intro course I taught last Fall except geared towards high school students and compressed into a 3-4 week chunk instead of 13 (it is for a Summer academy program that offers selected high school students a chance to try out college-caliber courses in technology). With those parameters, Python makes the most sense because it has little cruft when dealing with programming fundamentals and the language transfers well to whatever the student does next (programs on their own, goes to college and takes an actual undergraduate intro cs class).
At the introductory level, both imperative and functional styles ought to be taught because they require distinct reasoning skills (invariants vs. abstraction) that a computer scientist needs to be able to exhibit. Currently, the majority of the field teaches almost exclusively the former but the tides are slowly changing both at the grassroots level (e.g., see CMU's principles of imperative and principles of functional programming courses) and at the policy level (e.g., see the Computer Science Curricula task force 2013 report).
It's funny, MIT's Intro to CS Serious course is still done in LISP i think.
It is nice that functional thinking has come to the forefront recently, personally, i think that it's due to JQuery of all things, but syntacitical sugar for anoymous functions in python, c#, scala and others exposed a lot of people to the style. it's a good thing, because shifting away from this obsessive compulsive disorder about OOP is way overdue.
MIT has moved from scheme to Python, actually. Northeastern still does everything in Racket. Here at Penn, we've moved from Java to Java+OCaml. Elsewhere people are considering transitions from Java to Python as well, but I think there's a lot of programs holding their breath for the final word from the Curricula task force before they start overhauling.
i guess the question is python 2.x or 3.x ... there's a forking going on :-)
Java is awful for a foundation class. At least with C you forced people to work close to the metal. With Python, you get away from template coding, and hide some of the uglier features of C and C++... Honestly, it seems like a clear choice for intro classes.
For most definitions of an intro class, the concepts that you are teaching don't require you to be anywhere near the metal. So what drives what programming language you use in the class comes from external factors as well as internal (e.g., expectations of other departments and courses downstream within the major).
yeh, looking back on it, being close to the metal isnt nearly as needed as was 20 years ago :-)
Ah yes, forgot about the primitive restriction on sync blocks. You're right. Creating a new object that houses the shared value is the right thing to do. You can also remove synchronized on ThreadingExample.output. And alternatively, you can push the synchronized block onto the methods of your ThreadingExample which makes things slightly more fine-grained although then you get potential interleavings within the debug printlns of output.
So, synchronization on a method only works if the new thread is spawned within the same object? Unless you make the method static?
Think of it as protecting resources that are shared across multiple threads. The effect of synchronized is to say that "no one else can access this resource until I am done with it". Then the question becomes what resource you are protecting when you use synchronized. When you synchronize a method, you are protecting the object that the method is invoked on or the class object if the method is static. Whether this is what you need depends on your particular situation (although in practice, it tends to be too coarse-grained for what you need).
@TwitchTV, @Youtube: master-level zerg ladder/customs, commentary, and random miscellany.
Is there another way to do concurrency in Java, without extending Thread? I vaguely recall that.
Not sure what you mean by that. Threads are a fundamental concept in traditional concurrency. You can't really "not" deal with them in the sense that they are how you achieve concurrent computation.
If you're instead talking about synchronized/locks (which is what causes headaches when dealing with shared-memory concurrency) then as Bowen described above, java.util.concurrent provides a variety of lock-free data structures, futures, and atomic variables for you to use.
If you really mean alternatives to threads, then you are really talking about different models of concurrency, e.g., hoare's channels and tuple spaces. There are library implementations of these concepts (I believe) but they are not necessarily production-ready, well understood by the masses, or otherwise fit for commercial use. You'll need to go to other languages, e.g, go, for those.
@TwitchTV, @Youtube: master-level zerg ladder/customs, commentary, and random miscellany.
Posts
If you ever need to talk to someone, feel free to message me. Yes, that includes you.
Some shenanigans with my degree audit really screwed me over. Learning Intro to C was how all CS and CompEngineers start out, then they move on to CS1. This part is fine. The CS1 course used C to teach data structures and binary trees. What messed me up was that my degree audit was old, so I ended up taking OOP (java) and CS2 (which assumed you already took Java) simultaneously. Trying to do the coursework was a nightmare but the tests were easy.
Now, I had been doing stuff through the Majors/Requirements controller, but it seems like those aren't a good fit for what I'm thinking about here:
User goes to site -> User picks major from list -> User selects completed courses -> User sees courses remaining + suggestions for next semester
Before I go zooming off into the distance, my thinking right now is that I should be using the Sessions controller.
User goes to site -> new session
User picks major from list -> result stored in session
User picks completed courses -> results stored in session
Logic performed on selections, results displayed.
Is this right? It just seems like defining actions on the Requirement/Majors controller doesn't seem right (as those would be if I was creating a new/updating an old instance of those).
Also, is there an IRC room for this thread? I feel like I have been clogging things up with dumb ol' Rails questions.
When a User picks a major is that supposed to be an action that permanently (barring a later remove action) associates that user with that major? If so, you should have a database association between users and majors. A Sessions controller is a good thing to have, but you shouldn't be using it to handle actions involving majors or courses (I'm not 100% sure that's what you were suggesting, but it seemed like it). The Sessions controller should exclusively handle creating/updating/deleting sessions -- i.e. signin/signout.
It sounds to me like what you want is to have a many-to-many relationship between majors and requirements, then you add the embedded resource to your router. Then if your user picked the major with id 3, the route would look like this:
/majors/3/reqs/index
with an edit action for a req with id 5 looking like
/majors/3/reqs/5/edit
for example.
Hm that would probably work okay as a hammer using the top part of the curve.
Maybe you meant this kind of hammer:
Here's the code I'm using:
Also I'm wondering if because you're not accessing any variables, the JRE assumes that it's safe to let them both enter at the same time. Edit: nevermind I see the output++ there now.
:^: :^:
You warm the cockles of my heart Uratonky. If it breaks once, with concurrency, it's likely that it will break consistently.
Also, the output doesn't look wrong to me. You've got a semaphore on output only, meaning you can't have concurrent output. Since the sleeps are random, I think one thread can go twice before the other, no?
Is the example actually Duck/Wabbit season? Because that would be awesome.
Nah that was me. :P I figured that since it'll be repeating it's better than Jamaica and Fiji.
http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/locks/Lock.html
Or use a semaphore of some variety. I find locks to be simple so long as you rule out race conditions preventing your app from working.
http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.4.3.6
In your particular example (the original version), each ThreadingExample instance grabs its own particular lock, so there is no blocking that occurs. And also note that the counter is not shared between the threads because it is non-static which probably defeats the purpose of the exercise. What would work is making the instance variable a static variable instead and then using a synchronized block:
Rather than a method-level synchronized annotation.
PHP is a balsa wood paint stick and an unpolished sandstone held separately in each hand
Don't assume bad intentions over neglect and misunderstanding.
Why would you need to synchronize two objects accessing their own internal variables?
And it seems to give me a better idea of how synchronization works.
Python has a clearly defined blocking structure, its a colon (:) followed by a change in indentation, the block is marked by a change to previous indentation.
It's not that "whitespace is meaningful", or that there are no delimiters, its that the delimiters are differently defined. They're purposefully chosen this way to make the code more readable, as code is read much more often that it's written.
no, its exactly those things that make it a bad intro language.
"here, install this ubuntu CD... ok, open a console, type "python" type "print 'hello world'" is far simpler to understand.
yeh, looking back on it, being close to the metal isnt nearly as needed as was 20 years ago :-)
Joe's Stream.
Think of it as protecting resources that are shared across multiple threads. The effect of synchronized is to say that "no one else can access this resource until I am done with it". Then the question becomes what resource you are protecting when you use synchronized. When you synchronize a method, you are protecting the object that the method is invoked on or the class object if the method is static. Whether this is what you need depends on your particular situation (although in practice, it tends to be too coarse-grained for what you need).
Don't assume bad intentions over neglect and misunderstanding.
I really don't know what I was thinking with thise code tbh, Java is so wtf compared to my equivalent code in C++ or C#.
Not sure what you mean by that. Threads are a fundamental concept in traditional concurrency. You can't really "not" deal with them in the sense that they are how you achieve concurrent computation.
If you're instead talking about synchronized/locks (which is what causes headaches when dealing with shared-memory concurrency) then as Bowen described above, java.util.concurrent provides a variety of lock-free data structures, futures, and atomic variables for you to use.
If you really mean alternatives to threads, then you are really talking about different models of concurrency, e.g., hoare's channels and tuple spaces. There are library implementations of these concepts (I believe) but they are not necessarily production-ready, well understood by the masses, or otherwise fit for commercial use. You'll need to go to other languages, e.g, go, for those.