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
CptAJ
Sep 15, 2007
El Capitanisimo
Quick question: I've started watching some of MIT's Open Courseware lectures on computer science. They're pretty cool but as you can see here, not that many of the courses are available in video lecture form.

Is there another OCW-type program that has better CS materials?

Adbot
ADBOT LOVES YOU

Eclipse12
Feb 20, 2008

Triple Tech posted:

:master: People who don't know anything about the construction of virtual products think they can be made in Internet time.

Try reading my post next time. I said I didn't know how to code; I never said that I hadn't asked someone who does how long my idea would take to make.

csammis
Aug 26, 2003

Mental Institution

Eclipse12 posted:

Try reading my post next time. I said I didn't know how to code; I never said that I hadn't asked someone who does how long my idea would take to make.

That's right, you never said it. No one can read your post and figure out what you didn't say. Hope you're better with software requirements than with forum posting!

tef
May 30, 2004

-> some l-system crap ->

Eclipse12 posted:

Try reading my post next time. I said I didn't know how to code; I never said that I hadn't asked someone who does how long my idea would take to make.

I did read your post, that's why I asked for clarification :3:

floWenoL
Oct 23, 2002

Eclipse12 posted:

Try reading my post next time. I said I didn't know how to code; I never said that I hadn't asked someone who does how long my idea would take to make.

Here's another thing you didn't say: what the project actually is.

Eclipse12
Feb 20, 2008

floWenoL posted:

Here's another thing you didn't say: what the project actually is.

See, this is what I wanted to avoid. All I was really wondering was where I should post if I'm looking for work on a project. I didn't want to make a new thread for it if that's not how things are done here. I've never come to the PC forum before, so I didn't know the ettiquette and wanted to check before making a new post about it.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Eclipse12 posted:

I've never come to the PC forum before, so I didn't know the ettiquette and wanted to check before making a new post about it.

Well one bit of etiquette is not to ask non-programming questions in the programming questions thread! It honestly would have been less bad if you'd just made a thread. Not that this is to imply that we wouldn't make fun of you in a different thread. :angel:

Flamadiddle
May 9, 2004

Probably a really stupid question, but I have a question about for-each loops.

I fully understand how to use them and what they do, but is there any reason (above readability) to use one in place of, say, a for loop stepping through an array? Is there a performance improvement either way?

Edit: I'm more specifically talking about Java here, if that makes any difference.

tef
May 30, 2004

-> some l-system crap ->

Flamadiddle posted:

I fully understand how to use them and what they do, but is there any reason (above readability) to use one in place of, say, a for loop stepping through an array? Is there a performance improvement either way?

Readability is a fantastic reason to write code that way. I highly doubt there will be significant performance overheads either way.

Optimization: Just say no.


Edited to Add:

Accessing by index might be faster in theory, but the code will have to do boundary checks and the compiler will have to eliminate them. Meanwhile inlining iteration is simpler. On the whole I doubt that what the code compiles to will look significantly different, if at all different (depending on the data type)

Besides you should be using collections and avoid arrays :3:

Flamadiddle
May 9, 2004

Thanks for that. Will go and read up on collections this evening.

RussianManiac
Dec 27, 2005

by Ozmaugh
for-each is also good for iterating over anything that inherits from Collection such as maps, sets, linked lists, etc.

I think for-each is best when you just want to access and modify each element but not when you want to delete it. In that case you will run into concurrent modification exceptions.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

RussianManiac posted:

anything that inherits from Collection such as maps
They don't.

quote:

I think for-each is best when you just want to modify each element but not when you want to delete it.
You can't.

quote:

In that case you will run into concurrent modification exceptions.
It won't.

Mulloy
Jan 3, 2005

I am your best friend's wife's sword student's current roommate.
I have a dumb question that's somehow made it to me despite being the least qualified to answer this.

We have a service which allows you to use a URL to launch various tools on our side which are made from an in house scripting tool. However, when you enter the URL, it returns an ID for the created instance for reference as a new web page.

One of our customers is using this to let their end users do various things, but does not want to have the return page with the ID show up.

Is there a way in HTML to suppress this return page from appearing when their end user hits submit, or to redirect to a different confirmation page?

I assume it's a simple thing, but googling turned up nothing.

Thanks!

RussianManiac
Dec 27, 2005

by Ozmaugh

Mustach posted:

They don't.

You can't.

It won't.

Collection has method to return iterator, although specifically it appears that class has to implement http://java.sun.com/javase/6/docs/api/java/lang/Iterable.html to be allowed in for-each loop.

You most definitely can delete elements from some Collection while inside for-each loop. I guess what I should have said is that some classes do not support this, and if they do you should be calling remove() method on the iterator, which I am not sure how to do if you are using for-each loop because the variable it gives you is reference to element inside collection itself not the iterator.

If you had for-each loop over a Set and tried calling remove on the set with the current element, you most definitely will get concurrent modification exception.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Flamadiddle posted:

Probably a really stupid question, but I have a question about for-each loops.

I fully understand how to use them and what they do, but is there any reason (above readability) to use one in place of, say, a for loop stepping through an array? Is there a performance improvement either way?

Edit: I'm more specifically talking about Java here, if that makes any difference.

wikipedia posted:

Unlike other for loop constructs, however, foreach loops [1] usually maintain no explicit counter: they essentially say "do this to everything in this set", rather than "do this x times". This can potentially avoid off-by-one errors and make code simpler to read.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

RussianManiac posted:

Collection has method to return iterator, although specifically it appears that class has to implement http://java.sun.com/javase/6/docs/api/java/lang/Iterable.html to be allowed in for-each loop.
I misunderstood you on the deletion part, but Map is not a Collection or an Iterable.

RussianManiac
Dec 27, 2005

by Ozmaugh

Mustach posted:

I misunderstood you on the deletion part, but Map is not a Collection or an Iterable.

Yea I think you are right. What I do is just iterate over keySet. is that efficient?

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
The docs say that it's backed by the Map, so probably.

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
I don't see why a map shouldn't be iterable, assuming it's based on an rbtree or some other balanced bst



e: or a skiplist :3:

RussianManiac
Dec 27, 2005

by Ozmaugh

Otto Skorzeny posted:

I don't see why a map shouldn't be iterable, assuming it's based on an rbtree or some other balanced bst



e: or a skiplist :3:

in C++ STL its iterable :D

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Java maps are not collections directly, but do provide three collection views — keySet, values, and entrySet. All three are just views over the existing map and do not require copying internal structures. You can generally remove but not add entries through these collections, although entry sets generally allow both; otherwise their implementations are complete, and usually defined in the obvious ways in terms of the map.

It's generally better to iterate over an entry set than the key set, because in most implementations it avoids a bunch of unnecessary map-lookups, but the types involved to be really gratuitous; e.g. Iterator<Map.Entry<String,List<MyObject>>>. A respectable entry set implementation will avoid allocating a new Map.Entry object for every entry in the map, either by making the internal structures implement Entry or by creating a single Entry instance for the entire iteration (usually coincident with the iterator).

foreach loops are really nice sugar as long as you don't need an explicit reference to an iterator or an index.

RussianManiac
Dec 27, 2005

by Ozmaugh

rjmccall posted:

Java maps are not collections directly, but do provide three collection views — keySet, values, and entrySet. All three are just views over the existing map and do not require copying internal structures. You can generally remove but not add entries through these collections, although entry sets generally allow both; otherwise their implementations are complete, and usually defined in the obvious ways in terms of the map.

It's generally better to iterate over an entry set than the key set, because in most implementations it avoids a bunch of unnecessary map-lookups, but the types involved to be really gratuitous; e.g. Iterator<Map.Entry<String,List<MyObject>>>. A respectable entry set implementation will avoid allocating a new Map.Entry object for every entry in the map, either by making the internal structures implement Entry or by creating a single Entry instance for the entire iteration (usually coincident with the iterator).

foreach loops are really nice sugar as long as you don't need an explicit reference to an iterator or an index.

yea I usually iterate over keySet because it makes more sense for most algorithms involving maps. I haven't found a nice way to delete stuff from Collection while using foreach loop, is there one?

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
I was kind of hoping there was a rationale provided for maps not being collections directly

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

RussianManiac posted:

yea I usually iterate over keySet because it makes more sense for most algorithms involving maps.

Why? Usually you want both the key and the value, which is exactly what entrySet is for.

RussianManiac posted:

I haven't found a nice way to delete stuff from Collection while using foreach loop, is there one?

Nope; you'll have to go back to using an iterator --- or better yet, removeAll if you can swing it.

Otto Skorzeny posted:

I was kind of hoping there was a rationale provided for maps not being collections directly

Ontologically, it seems correct that a map shouldn't be a collection, but that it's straightforward to view it as one. But everyone has their own views here.

Practically, making Map a collection of entries would require awkward overloads for a few methods like remove(). It would also tempt novices to use methods like add() instead of put(), with disastrous results --- recall that the collections hierarchy went in long before generics.

MagneticWombats
Aug 19, 2004
JUMP!
I was thinking of using mono for something so that I can run the program on linux and windows and because I like C#. However, there seems to be some sort of sperger war going on between Miguel de Icaza and RMS. So should I trust my gut feeling and use mono anyways because RMS is probably spergin' about nothing or does he have a valid case? Trying to form my own opinion is difficult because this seems to have turned into a religious war of some sort.

tef
May 30, 2004

-> some l-system crap ->
The hard bit will be cross platform libraries.


I would ignore RMS talking about stuff that will be unlikely to affect you.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



tef posted:

The hard bit will be cross platform libraries.

http://www.mono-project.com/GtkSharp would probably work pretty well.

quote:

I would ignore RMS talking about stuff that will be unlikely to affect you.

It's usually best to ignore the ranting of the deeply paranoid

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
My experience in computing has been that the value of a person's opinions is directly proportional to their physical appearance and hygiene. Stallman is a hideous forest creature who eats things he picks off his feet. Nuff said.

raminasi
Jan 25, 2005

a last drink with no ice
What's the reason for using anonymous namespaces instead of the static keyword to achieve internal linkage? Is it just customary?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

GrumpyDoctor posted:

What's the reason for using anonymous namespaces instead of the static keyword to achieve internal linkage? Is it just customary?

Classes can't be declared static.

raminasi
Jan 25, 2005

a last drink with no ice

Avenging Dentist posted:

Classes can't be declared static.
Ah, that makes sense.

flappin fish
Jul 4, 2005

CptAJ posted:

Quick question: I've started watching some of MIT's Open Courseware lectures on computer science. They're pretty cool but as you can see here, not that many of the courses are available in video lecture form.

Is there another OCW-type program that has better CS materials?

http://webcast.berkeley.edu/ has video and audio lectures for some things, although they don't organize it as well as MIT does.

Krang
Nov 19, 2002

CptAJ posted:

Quick question: I've started watching some of MIT's Open Courseware lectures on computer science. They're pretty cool but as you can see here, not that many of the courses are available in video lecture form.

Is there another OCW-type program that has better CS materials?

There's also some stuff from Stanford here:

http://see.stanford.edu/see/courses.aspx

Hillridge
Aug 3, 2004

WWheeeeeee!
This is more of a scripting question than programming, but I didn't want to start a whole new thread for it. Is there a way for me to write a .reg file that will edit a user specific key like HKEY_USERS\S-1-5-21-blah-blah-blah-123456\Software\Microsoft\Internet Explorer\Main, but that will work for any user on any machine?

I want a way to restore a homepage by clicking a reg file.

Edit:
I tried using HKEY_CURRENT_USER again and got it to work.
I was changing the wrong key before, which is why I thought it wasn't working.

Hillridge fucked around with this message at 16:19 on Oct 5, 2009

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
I'm trying to think of a simple set of rules to determine if "6-1" should be interpreted as 6:00AM-1:00PM or 6:00PM-1:00AM. The one closer to normal business hours is the 'correct' one. I feel like this should be really simple, but I just can't think of what it is.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

fletcher posted:

I'm trying to think of a simple set of rules to determine if "6-1" should be interpreted as 6:00AM-1:00PM or 6:00PM-1:00AM. The one closer to normal business hours is the 'correct' one. I feel like this should be really simple, but I just can't think of what it is.

Distance in hours between centers of time (a la center of mass).

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Avenging Dentist posted:

Distance in hours between centers of time (a la center of mass).

As in, the distance between the center of the input time and the center of the business day? What about for an input of something like "5-6" ?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

fletcher posted:

As in, the distance between the center of the input time and the center of the business day? What about for an input of something like "5-6" ?

Center of business day (9-5): 1 PM
Center of input: 5:30 XM

5:30 PM - 1 PM = 4.5 hours
1 PM - 5:30 AM = 7.5 hours

The answer should be clear.

You probably mean something like 6-8, in which case just pick one. Or you may also want to massage the center of your business day if people don't like getting up as rear end o'clock for a meeting.

Avenging Dentist fucked around with this message at 22:13 on Oct 5, 2009

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender
An alternative heuristic that gives slightly different answers than the center-of-business-day option is to enumerate the hours in each candidate range, give one point for hours that are in the normal business day, and subtract one point for hours that are not. So, (5,6) enumerates to:
5 - 6 : -1 point
5 - 18 : 3 points
17 - 18 : -1 point
17 - 6 : -13 points
And sorting reveals (5,18) as the most sensible interpretation.

This method is nice if you like tweaking, because instead of the one point for/one point against metric, you can easily adopt to a table with a score for each hour of the day, based on presumably real data like the average number of people in the office at that hour. It won't be very different than the results you'd get from AD's suggestion, but you can pretend it's better.

Adbot
ADBOT LOVES YOU

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
Awesome! Thanks guys!

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