Search Amazon.com:
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 $3,400 per month for bandwidth bills alone, and since we don't believe in shoving popup ads to our registered users, we try to make the money back through forum registrations.
«262 »
  • Post
  • Reply
csammis
Aug 26, 2003

Mental Institution

Goodness the old one had been going a long time

A Paradigm Shift: This thread is now for generic questions about coding, and language-neutral short programming questions (or languages for which there isn't already a megathread). If you've got a question about a specific language, and there's a megathread for it, better to post it there where the language-specific dorks experts will see it.

THE MEGATHREADS

Apple App Development: iOS (iPhones and iPads), Mac OS X, Xcode, Cocoa

C/C++ Programming Questions Not Worth Their Own Thread

Cavern Reading List - Recommend and Request reading material

Flash Questions Megathread

Java questions which don't deserve their own thread, yet.

Game Development Megathread

Want to Learn Haskell?

.Net (C#, VB.NET [VB 2003, 2005, and 2008]) Questions Megathread

The Perl Short Questions Megathread: executable line noise

<?PHP questions that don\\'t need their own thread ?>

Python information and short questions megathread.

Ruby on Rails Love-In

Scientific/Math(s) Computing: numerical/statistical analysis tools and CASs - R, Matlab, etc.

SELECT * FROM Questions WHERE Type = 'Stupid'

Small Excel questions that don't deserve their own thread

Version Control Questions Megathread (SVN / git / whatever else)

Web Design/Development Small Questions - Rev Holy Grail

If I missed one, or a new one appears, PM me to get it listed here


HOT GOON ACTION

Now you too can chat with real life nerds, 24/7 because we don't have lives or sleep! Join the CoCs at #cobol on irc.synirc.net, we are happy to answer your questions while mocking you and randomly replacing words with "butt."

Don't like talking to or looking directly at nerds but want to gain their power, just like Highlander?! Check out http://sn.printf.net/, the CoC goon blog aggregator. Read more about it here, right here

csammis fucked around with this message at Oct 22, 2012 around 11:49

Adbot
ADBOT LOVES YOU

csammis
Aug 26, 2003

Mental Institution

Let's get this party started:

Jose Cuervo posted:

poopiehead, do you know of a good way to search for a particular key in a dictionary without actually knowing the key, but only a unique characteristic? I know that the key I am looking for is the one the has the longest string length (and there is a key with a longest string length in my dictionary). Right now I am useing the following loop to get the key:
code:
         For Each key As String In myDic.Keys
            If key.Length > theLongestKey.Length Then
               theLongestKey = key
            End If
         Next
where I initially have theLongestKey set as an empty string. This works, but I thought there might be a cleverer (and hopefully more efficient) way to do it.

Note, this is a good example of a question that belongs in this thread because it's language-agnostic


Iterating through the keys to find what you're looking for is the only way to do it at any given time, unless you want to use a "compiler solution" and throw another list at it that consists the keys sorted by the property you want, which you would add to whenever you insert a new key into the dictionary. I can't really imagine that there's a good reason to do this.

But along those lines: Wherever you're adding an entry to the dictionary, how about you just add a check to see if the key that's being added satisfies the property you want, and save it?

Jose Cuervo
Aug 25, 2004


csammis posted:

But along those lines: Wherever you're adding an entry to the dictionary, how about you just add a check to see if the key that's being added satisfies the property you want, and save it?

I think I am going to go with this method. On a related note, (although this is VB specific), if I wanted an array or a dictionary to be accessible by any function in any part of my code (even if it is in a different class), what would I need to put in my main to do that?

I would prefer the array/dictionary to be read only, but this is not crucial.

Save the whales
Aug 30, 2004

by T. Finn


I'll state my question using Java terminology, but I'm curious as to whether there's a general name for this kind of data structure.

Recently I came upon the need for a data structure that is a bit of a cross between a Map and a Set. I ended up calling it BinaryRelation<L, R>. Its most important methods are:

code:
/*
pairs the given left-hand and right-hand values
*/
void put(L left, R right);

/*
returns a collection view of the left-hand values paired with the specified right-hand value
*/
Collection<L> getLeft(R right);

/*
returns a collection view of the right-hand values paired with the specified left-hand value
*/
Collection<R> getRight(L left);
It's kind of like a bidirectional map in that you can find associated values for keys or associated keys for values, but it's different in that neither keys nor values must be unique - only key-value pairs must be unique.

I've already written the Java code to implement this, so I'm not asking how it can be done, but I'm curious - is there a general name for this kind of data structure? Has it been implemented in any popular programming languages or libraries? I wasn't able to find anything like this after a bit of Googling and I was surprised because it seems like such a useful way of describing a relation between two sets of objects. I know for certain I'm going to use it in every web application I make from here on out.

zootm
Aug 8, 2006

We used to be better friends.

That kind of relationship is referred to as "many-to-many" but I'm not sure what a data structure that implements it would be called. I've only ever seen this sort of thing in persistence libraries modelling the same thing in a database, but they don't tend to use a specialised structure. With one-to-one multiplicity this would be a "bidirectional map", but that's not what you've done here. Essentially you're just holding a list of graph edges with a specialised interface to it, as far as I can tell?

Edit: That last one basically answered itself. I think the data structure you've made is probably pretty much a graph data structure, and you could implement your interface with an adjacency list or an adjacency matrix pretty well. The interface just looked kinda strange . Since you differentiate left and right I guess you're essentially representing a directed graph as well.

zootm fucked around with this message at Feb 23, 2008 around 09:32

fret logic
Mar 8, 2005
roffle


What are some good resources/books on programming theory?

6174
Dec 4, 2004


fret logic posted:

What are some good resources/books on programming theory?

What aspect are you interested in? Algorithms? Data structures? Programming Languages (either specific language or in general)? Program design? Numerical Analysis? Operating Systems? Something else?

Also a bit about your background may help so you don't get recommended something that is either too simple or too hard.

fret logic
Mar 8, 2005
roffle


6174 posted:

What aspect are you interested in? Algorithms? Data structures? Programming Languages (either specific language or in general)? Program design? Numerical Analysis? Operating Systems? Something else?

Also a bit about your background may help so you don't get recommended something that is either too simple or too hard.

I'm just a CS freshman with little to no background in anything beyond basic Java/C syntax. Was just wanting to get some basic theory in my head while I'm learning these languages.

6174
Dec 4, 2004


fret logic posted:

I'm just a CS freshman with little to no background in anything beyond basic Java/C syntax. Was just wanting to get some basic theory in my head while I'm learning these languages.

In that case I'd recommend two books. First, The Practice of Programming by Kernighan and Pike. It will help get some good practices in your head and is a good choice for someone still pretty new to programming. Second is Code Complete by McConnell. It is a handbook of practical advice.

Avenging Dentist
Oct 1, 2005

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

fret logic posted:

I'm just a CS freshman with little to no background in anything beyond basic Java/C syntax. Was just wanting to get some basic theory in my head while I'm learning these languages.

If you want some "deep" theory, check out Knuth's "Art of Computer Programming" series (be warned, they are very, very math-heavy).

fret logic
Mar 8, 2005
roffle


6174 posted:

In that case I'd recommend two books. First, The Practice of Programming by Kernighan and Pike. It will help get some good practices in your head and is a good choice for someone still pretty new to programming. Second is Code Complete by McConnell. It is a handbook of practical advice.

I'll check those out, thanks! Should I wait until I have a language down pretty well to read Code Complete?

Avenging Dentist posted:

If you want some "deep" theory, check out Knuth's "Art of Computer Programming" series (be warned, they are very, very math-heavy).

duck monster
Dec 15, 2004

Never stop arguing about casual racism.


Avenging Dentist posted:

If you want some "deep" theory, check out Knuth's "Art of Computer Programming" series (be warned, they are very, very math-heavy).

This book is the Computer science version of Walter Pistons "Counterpoint" and "Harmony" , THE canonical bibles on music theory, but also complete brainfucks for people first reading them.

If you DO struggle through Knuth's works, do so reverently, Knuth may be hard , but you get that when dealing with the sacred texts of God himself.

Professor Science
Mar 8, 2006
diplodocus + mortarboard = party

Avenging Dentist posted:

If you want some "deep" theory, check out Knuth's "Art of Computer Programming" series (be warned, they are very, very math-heavy).
Oh that series that people have on their bookshelf so they can be like, "Oh, yes, I've read the Art of Computer Programming, yessssss, I am smoking a pipe now?"

6174
Dec 4, 2004


fret logic posted:

I'll check those out, thanks! Should I wait until I have a language down pretty well to read Code Complete?




If you've taken a course or two of programming, you'll be adequately prepared for a large chunk of Code Complete. Of course if you have less experience it may take longer to wade through, but with some motivation you could do it.

Also a note about Knuth's books. They are very good, but I'm not sure Avenging Dentist's warning is quite strong enough. To be able to digest any of it you'll want to have at least some experience with discrete math (proof techniques, some set theory, etc) and algorithms/data structures. For many topics TAOCP is the best reference you'll find. However it is very dense, and not really friendly to someone just starting out. I'd strongly recommend you look at a copy from the library before you even think of anything like buying them. If you look at them and find them to be too much, look for the book Concrete Mathematics by Graham et al. It is designed to contain the math one needs to tackle TAOCP and would be a good intermediary step (and I'd still recommend some discrete math before tackling Concrete Mathematics).

csammis
Aug 26, 2003

Mental Institution

Professor Science posted:

Oh that series that people have on their bookshelf so they can be like, "Oh, yes, I've read the Art of Computer Programming, yessssss, I am smoking a pipe now?"

Has this man read TAOCP?

poopiehead
Oct 6, 2004



Since you've already done some C, I'll recommend The C Programming Language. A lot of it will just be review, but it makes some things you might have a foggy understanding more precise and it's actually incredibly concise and accessible.

Depending on where you're going with CS, Mythical Man Month, Extreme Programming Explained, and Pragmatic Programmer are pretty great reads more focused on programming as a profession/art than CS theory. Probably want to wait a year or two for these or at least re-read in a few years though, not because they're hard(they're not), but because more experience puts them into context.

Alan Greenspan
Jun 17, 2001



fret logic posted:

I'm just a CS freshman with little to no background in anything beyond basic Java/C syntax. Was just wanting to get some basic theory in my head while I'm learning these languages.

http://www.cs.rochester.edu/~scott/pragmatics/
http://www.amazon.com/Programming-L...t/dp/1558604421

This book is extremely awesome.

Ranma
Nov 2, 2004

God I fucking love Diablo 3 gold, it even paid for this shitty title

What is a good book to learn database programming? I am starting a co-op where they do SQL programming, and we're coding with Java. I have no experience with SQL or database programming.

IcePotato
Dec 29, 2003

There was nothing to fear
Nothing to fear



Agreed, and the author is a great professor to boot

Scaevolus
Apr 16, 2007



fret logic posted:

What are some good resources/books on programming theory?
Structure and Interpretation of Computer Programs

Gesundheit
Sep 19, 2007



Seconding this. Especially for a beginner who has only learnt an imperative language yet.

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.

csammis posted:

Has this man read TAOCP?
Hahaha, I know him and can guarantee that he has not.

Professor Science
Mar 8, 2006
diplodocus + mortarboard = party

Oh, I guess if we're going to talk about algorithms books we should talk about CLRS. Probably the Dragon Book for compilers, Dinosaur Book for high-level OS concepts, Russell and Norvig for AI, Computer Systems: A Programmer's Perspective for an intro to systems programming...

kief olbermann
Jan 14, 2008



Need some help with one of the project Euler puzzles. It's the one where you have to find the largest prime factor of 317584931803. I made a method I called isPrime(int x), where you test x % (2 to x^1/2 inclusive) and if any of those is 0, it returns false, otherwise it returns true. Well that helper method worked for the smaller example case (largest prime factor of 13195), but when I tried it for 317584931803, it ran for several minutes and still didn't find the answer, so I killed it. I'm trying the fermat primality test instead for the smaller case, but it doesn't seem very accurate. I'm also worried that I might have problems using that algorithm for the larger case, since there is no nextLong method for the java Random class. Am I on the right track with using the fermat test? Is there another algorithm I should be using?

more falafel please
Feb 26, 2005



Professor Science posted:

Oh, I guess if we're going to talk about algorithms books we should talk about CLRS. Probably the Dragon Book for compilers, Dinosaur Book for high-level OS concepts, Russell and Norvig for AI, Computer Systems: A Programmer's Perspective for an intro to systems programming...

I didn't like the dinosaur book, Tenenbaum was much better.

Also, I would suggest Stevens - Advanced Programming in the Unix Environment.

Professor Science
Mar 8, 2006
diplodocus + mortarboard = party

more falafel please posted:

I didn't like the dinosaur book, Tenenbaum was much better.

Also, I would suggest Stevens - Advanced Programming in the Unix Environment.
isn't tenenbaum basically a source walkthrough of minix, though? that seems kind of silly.

zootm
Aug 8, 2006

We used to be better friends.

Professor Science posted:

isn't tenenbaum basically a source walkthrough of minix, though? that seems kind of silly.
I don't think it is. I seem to recall it gives a pretty detailed overview of the construction of various popular kernels.

more falafel please
Feb 26, 2005



Professor Science posted:

isn't tenenbaum basically a source walkthrough of minix, though? that seems kind of silly.

It's more the other way around -- minix is the example used in a book about how operating systems are written.

JawnV6
Jul 4, 2004

so hot...



What's top's interface called? I have a static program that polls the state of a few machines, I'd like to just wrap it up and have it constantly update to the same screen, but I don't even know what to search for to rip off how top prints out to the terminal.

Appa Time! posted:

Need some help with one of the project Euler puzzles. It's the one where you have to find the largest prime factor of 317584931803. I made a method I called isPrime(int x), where you test x % (2 to x^1/2 inclusive) and if any of those is 0, it returns false, otherwise it returns true. Well that helper method worked for the smaller example case (largest prime factor of 13195), but when I tried it for 317584931803, it ran for several minutes and still didn't find the answer, so I killed it. I'm trying the fermat primality test instead for the smaller case, but it doesn't seem very accurate. I'm also worried that I might have problems using that algorithm for the larger case, since there is no nextLong method for the java Random class. Am I on the right track with using the fermat test? Is there another algorithm I should be using?
317584931803 is larger than can be stored in an int.

more falafel please
Feb 26, 2005



JawnV6 posted:

What's top's interface called? I have a static program that polls the state of a few machines, I'd like to just wrap it up and have it constantly update to the same screen, but I don't even know what to search for to rip off how top prints out to the terminal.
317584931803 is larger than can be stored in an int.

I think top just uses ncurses, which is a generic console interface library, and basically what any console program with a UI at all uses.

kief olbermann
Jan 14, 2008



JawnV6 posted:

317584931803 is larger than can be stored in an int.

Yeah I should have mentioned that I used longs for the larger case. That's not the problem, my algorithm works it's just that it's worst case time is horrible for larger stuff, so I was looking for a better alternative.

JawnV6
Jul 4, 2004

so hot...



more falafel please posted:

I think top just uses ncurses, which is a generic console interface library, and basically what any console program with a UI at all uses.
Thanks.

Appa Time! posted:

Yeah I should have mentioned that I used longs for the larger case. That's not the problem, my algorithm works it's just that it's worst case time is horrible for larger stuff, so I was looking for a better alternative.
Don't check every single integer between 1 and x^.5, build a list of primes and check against just those?

narbsy
Jun 2, 2007


Appa Time!: did you take out the even numbers in your test? That can help a large amount. I.e. test 2, then skip by 2s from 3 on. Makes it go quicker-er. I did it in javascript and it finished pretty quickly, if I recall correctly.


Yeah, just tested now. It took about 30 seconds for 600851475143, the new number for problem 3.

narbsy fucked around with this message at Feb 26, 2008 around 22:04

Mister Biff
Dec 26, 2006



Really stupid question about Visual Studio 2008:

I don't normally write Visual C stuff, but I found a tool that I absolutely must have, and it was only available as source code. After a lot of rigamarole, I've managed to get a compiled .exe, but the file won't run on any other system!

The error is always the same: The system cannot execute the specified program.

I've tried installing the Visual C Runtime Libraries (for both 2005 & 2008) on my test machine, but it doesn't seem to make any difference. I know I'm probably being stupid, but I can't seem to figure out how to make this thing work.

P.S. -- I only have the following includes, which I don't think are anything out of the ordinary:
code:
#include <stdio.h>
#include <windows.h>
#include <lm.h>
#include <lmdfs.h>
I've also got NetAPI32.lib linked as a resource file, so that might be it, but I'm still baffled. Any thoughts?

Edit: Er, this may be more appropriate for the C/C++ thread... if so, just tell me.

fletcher
Jun 27, 2003

ken park is my favorite movie

Is it more common to write variables as someVariable or some_variable? I can't decide which to use. I like using someMethod() instead of some_method(), so I'm thinking it would make more sense to use some_variable.

6174
Dec 4, 2004


fletcher posted:

Is it more common to write variables as someVariable or some_variable? I can't decide which to use. I like using someMethod() instead of some_method(), so I'm thinking it would make more sense to use some_variable.

The popularity of that kind of style issue depends on the language in which you are working.

csammis
Aug 26, 2003

Mental Institution

Mister Biff posted:

Edit: Er, this may be more appropriate for the C/C++ thread... if so, just tell me.

Yes, either that or the .NET thread (as you're working with Visual Studio), but try the C/C++ thread first.

Avenging Dentist
Oct 1, 2005

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

fletcher posted:

Is it more common to write variables as someVariable or some_variable? I can't decide which to use. I like using someMethod() instead of some_method(), so I'm thinking it would make more sense to use some_variable.

Generally, I think it's best to pick one style and use it for both variables and methods. It just makes things more consistent.

kief olbermann
Jan 14, 2008



narbsy posted:


Yeah, just tested now. It took about 30 seconds for 600851475143, the new number for problem 3.

I tried your suggestion and used the new number for the problem, it still did the same thing, ran for about four minutes and I gave up. I'm skipping evens in the primality test and the main method that checks if it's a factor of 600851475143. What kind of prime test are you using?

JawnV6 posted:


Don't check every single integer between 1 and x^.5, build a list of primes and check against just those?

Could you elaborate on this? I kind of get what you mean, but how do I go about building that list?

Adbot
ADBOT LOVES YOU

6174
Dec 4, 2004


Appa Time! posted:

I tried your suggestion and used the new number for the problem, it still did the same thing, ran for about four minutes and I gave up. I'm skipping evens in the primality test and the main method that checks if it's a factor of 600851475143. What kind of prime test are you using?


Could you elaborate on this? I kind of get what you mean, but how do I go about building that list?

If you're more specific about exactly what you are doing someone can probably point out what you are doing that is slow.

Also the thing JawnV6 mentioned is known as the Sieve of Eratosthenes.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply
«262 »