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
Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Who loves pthreads? You, I hope!!

I could wax poetic about my complaints with my operating systems class, but suffice it to say that I'm a bit lost when it comes to the pthread part of the current assignment.

The assignment is to write a server for a subset of HTTP - technically, we do this three times: once using fork(), once using pthreads, and once using select() to handle concurrent queries. Since, strangely, he hasn't said word one about pthreads in class, I'm rather lost on this.

So we would like the server to be able to handle an arbitrary number of queries at the same time, so I would like to do something like

code:
if (accept(...) > 0)
{
  pthread_t theThread;

  pthread_create(&theThread, NULL, handle_connection, 0);
}
Where handle_connection is the entry point for the thread, etc, etc. But from what I can gleam from the internet, obviously, if another connection is attempted as the first one is still going on, the variable theThread will be overwritten and horrible things would happen, since (I'm told) each thread maintains a stack frame starting from the entry point to the thread, not the calling function thereof. So, what about

code:
if (accept(...) > 0)
{
  pthread_create((pthread *)malloc(sizeof(pthread_t)), NULL, handle_connection, 0);
}
? Obviously this is bad because we can't free that memory. So we have a chicken/egg problem, and yet I feel like this something that commonly happens in real-world software, so there has to be a solution (and, I would argue, a simple one at that).

Oh god, tell me what to do so I can go back to writing Java ( :v: )

Adbot
ADBOT LOVES YOU

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

You know what else is equivilent to a DFA? A regular expression.

hexadecimal posted:

Also he asked for what is the fastest
Where?

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

hexadecimal posted:

You're all just mad you cant manually resolve ambiguous BNF grammar!
We're mad because it's not at all the right choice for what he's trying to do. Also, yacc will not resolve an ambiguous grammar (unlike us, who can resolve ambiguous grammars of natural languages, unlike LALR parsers), either: it'll bitch about shift/reduce and/or reduce/reduce errors and make a set choice.

edit: also, I'm preeeetty sure a ton of work has gone into optimizing the poo poo out of perl/python/$LANGUAGE_OF_THE_WEEK's regex library anyway.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

I assume he's talking about A+/MS/Cisco/etc certification, in which case, not if you're interested in programming. At best, they'll be introductory data structures classes, and in the average case, they'll be strictly IT classes.

Regarding math: In high school, math was my lowest mark by a good 25% and I never bothered taking Grade 12 math. I spent two years as a music major before taking a CS course on a whim and loving it so much that I dropped out of university to take grade 12 math and precalculus. It turned out that those years away did me good, and I'm now going to be graduating with a math minor. If you're worried about your math skills, there's nothing wrong with going to a local college and brushing up your knowledge.

Another question that should be asked is, what do you want to do with your programming knowledge? This would affect what choice of language you should approach. You mentioned that you're looking at the job market, then as before, I'd echo the Java and PHP suggestions, and throw in C# as well, since IMHO it's the most tolerable of the big enterprisey languages (assuming you're on a Windows machine). Given this, I wouldn't even bother learning C and certainly not C++.

Alternately, if you're a Mac user, I have heard it said that the Mac development world is booming thanks to the iPhone, so if you're a Mac person, learning C and then Objective-C might be a path to success for you.

Also, I disagree with your "That said, I realize it's important to know as much as you can." quotation - the way I read it, it sounds like you're suggesting a breadth of languages is important, and that's not the case; you are far more employable with knowing one language very well as opposed to knowing the rudiments of five.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

It's hard to say how that certificate would go; to be sure, it would give you a foundation, but you'd still have to build on it on your own time afterwards to make yourself marketable, in my view. One year really isn't enough to get deeply into the field, IMO.

IntoTheNihil posted:

Honestly, i'm not sure. I've always loved working with computers and want to eventually have a career in the field. The idea of being a game developer always looms but I don't really feel I should shoot for that. I am always thinking up programs and games but don't have the skills to create anything, so i'm looking to change that.
So, make no mistake: if it's game development that you're keen on, then you will absolutely require a great amount of math, and most likely a university degree.A friend of a friend works at Bioware with only the Canadian equivilent of an associate's degree (two years at a polytechnic), but he would be the exception to the rule. A brilliant friend of mine was offered a job at Bioware after he graduates from university, but even then he'd only be doing toolset development gruntwork*.


IntoTheNihil posted:

I've always thought that knowing multiple languages really opens up your career possibilities.
While that's true, given that you're starting from first principles I still maintain it's better to focus on a particular skillset rather than trying to be a jack-of-all-trades. Perhaps others will weigh in on this.

*I live in the town that Bioware is based in; hence why both my gamedev stories involved that one company.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

HungryHobo posted:

I was wondering if anyone here could give me some sugestions for sites to read, books or decent beginner projects in this area.
My school is big in ML, and if you told them that it was only good for boardgames, they'd go into conniptions :v:

If you're looking for an excellent overview of AI, in my view you can't go wrong with the Russell/Norvig text. Very complete and entertaining to read, even for someone like me who didn't really enjoy his AI class.

I guess the question is, what specifically did you like? Search? If so, adversarial search (minimax / alphabeta, etc)? Bayesian nets? Machine learning? If so, what specifically? Reenforcement learning? Vision? (If the answer to this question is "er, I donno", then the Russel/Norvig might be good in singling down especially what you like)

Also, talk to professors at your college who work in AI/ML. It's an excellent way to get yourself thinking about what they research, and maybe even working for them as an undergraduate summer research student.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

IntoTheNihil posted:

Sorry to spam up this thread with even more questions but I've recently discovered how huge the Java market really is. Even around my city there's multiple high paying jobs for Java programmers. Can anyone tell me the pros and cons of the language and some general learning info? I messed with it a bit before and even though people say it's simple I couldn't grasp much.
Java, you'll find, is a controversial language around a lot of places since it's (misguidedly, many would argue) used as a teaching language in most universities. Also, I wouldn't call it "simple" - doing a simple "hello-world" printing program requires a lot of keywords that a beginner won't really have a grasp on. That being said, for all intents and purposes there's nothing wrong with the language, so long as you can grok the object-oriented programming paradigm (this is where that 1 year program you talked about might come in handy--a lot of people need an instructor to really get it).

One of the best things that Java has going for it, in my view, is Sun's documentation. There are many tutorials on Sun's website, and the reference material is quite robust.

Start small and work up slowly, don't get discouraged, and have fun. :)

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

I disagree. There's no reason to know anything about the C memory model if you're learning Java to become a Java developer. Yes, it's something that everyone should know about in a perfect world, but given that he's starting from first principles I think it's best to choose a level of abstraction and stick with it. He can always come back to the lower-level stuff if he so chooses.

One of the good things about Java is that it does force you to code in a certain way; with C++, your methology can range from "procedural programming with iostreams" to "C with classes" to "Java-style OOP where most everything is a class" to "template metaprogramming and C++0x draft standard wankery" and everything in between. Given that he doesn't have an instructor guiding him, a more restricted language is probably what he needs, and the fact that he's looking at Java jobs is the icing on the cake in my view.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

dancavallaro posted:

Anyone know of a programming language where you can redefine integer literals (i.e. 3 = 5)?
In all seriousness, I meet at least one CS grad student per year who thinks that thinks there's some mystical block of memory that defines integers. :suicide:

edit: dancavallaro, are you a grad student? :raise:

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Well, of course, if it's horrible, INTERCAL will let you do it :v:

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Offhand, I don't know of a Linux analog to TextMate. From my experience, you'll have editors fall into three camps: the IDEs such as Eclipse or NetBeans, the generic NotePad-ish editors like gedit, and then the "real man"'s editors: vim and emacs. (which I would argue could very well be what he wants)

Not to turn this question into an editor holy war, but since I'm a vimfag, I would recommend you look at vim. It supports tabs, and you can get a directory tree by typing :e. You might need something like one of these plugins and a bit of scripting to make it really work the way you want, though. I'm sure emacs can be configured to do a similar thing, too; someone else would have to chime in on that, though.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

So I'm taking a computational differential equations class this term, which has a project component. I'd like to do my work in something that isn't Matlab. I assumed that any real scientific computing, based on the limited set of applications that I've used, would have to be written in some unholy alliance of C and Fortran. However, I came across SciPy and it sounds like they're trying to market Python of all things as a scientific computing language. Anybody have any thoughts about if this is a direction that things might go in, or is this nothing more than a bunch of Python dorks with Not Invented Here syndrome not wanting to link against LAPACK?

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

bitprophet posted:

Uh. SciPy has been used for years and in some areas (like bioinformatics) Python is basically the king.
No kidding, I had no idea :) Great, that's good to hear. Thanks.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

bitprophet posted:

No prob, sorry for sounding acerbic, was kind of defensive given your "golly they're using Python for this?!" tone ;)
Ha, no, it didn't bother me, especially since I (without ever having considered it) never really regarded Python as a language particularily suited to this sort of stuff, so you pretty much read my tone correctly :)

Since you're a Python guy, any idea what the speed hits are with using SciPy's routines as opposed to, say, a reasonable BLAS library?

edit: oh hey there's a python thread; why don't I go post in there instead :f5:

Dijkstracula fucked around with this message at 23:26 on Feb 11, 2009

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

ShoulderDaemon posted:

This is how it's typically done in mathematics.
Indeed, the "3 o'clock" 0 is how it always is. Not to put too fine a point on it, but taking some time to understand how the unit circle works will help immensely, especially this image.

Dijkstracula fucked around with this message at 07:19 on Feb 19, 2009

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

This may not be the best thread to ask this, but does anyone know how public nethack servers that you connect to over telnet handle ncurses running over different sockets? I'm working on something similar, and I was hoping to use some screen-handling API, but it doesn't appear that ncurses really is intended to write to use anything other than stdin/stdout. Thoughts?

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

ShoulderDaemon posted:

For the most part, they arrange a pty for each socket, then spawn a separate process for each pty that the ncurses code runs in (talking on stdin/stdout), and do anything fancy with IPC.
Blech, this doesn't sound like it will play nicely with my poll()/select() server. :( Sounds like I'll have to come up with something myself - all I really need is something to handle terminal control codes and some very basic window layout.

ShoulderDaemon posted:

ncurses and terminfo are seriously the worst code.
Whoever thought (y,x) is a good coordinate system should be strung up by his graybeard :mad:

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

ShoulderDaemon posted:

If you find yourself reimplementing the terminfo library, I may be able to give you some pointers; I've done partial reimplementations myself.
Thanks for this; I may take you up on this once I've thought the new problem through better (ie. it only just occurred to me that I won't have a SIGWINCH if I'm just dumping poo poo through a socket, so a lot of what I'm doing has to be thrown out the window)

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

ShoulderDaemon posted:

Telnet clients should send a window size option when they resize, so that's not a major problem. Feel free to email me if you'd rather not clutter the thread, jblake@omgwallhack.org.
Will do. Thanks again. :)

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

If you don't mind getting your hands dirty with a backtracking logic language like Prolog, this sounds like a good constraint programming problem.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Fruit Smoothies posted:

I agree that in order to solve a problem you need to know about it. However, in this case, it would only confuse people if I gave the whole subject matter.
Did it occur to you that maybe people are simply curious about what the problem domain is? You have a lot of people spending a nontrivial amount of time writing code for you and the least you could do is provide a bit of context for their interest.

In the worst case, people might get a glimpse into an area that they don't know anything about.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Munkeymon posted:

Java? When the hell did Java become good at anything graphical?
Hey now, AWT is pretty good by 1994 standards. :colbert:

But yes, at the risk of replying to every newbie question with "PYTHONPYTHONPYTHON", what you want is what Munkeymon said.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Is there any particular reason why ASCII control codes (say, "^[[2J", to clear the screen), would be filtered out by a Telnet client? My server echoes everything that's transmitted, and it does it on the local side, so I know the control code is correct, but on the client side nothing happens. Anything obvious that I'm likely to be missing?

I ask for IAC extended ASCII just to be safe, and that doesn't change anything.


Disregard, off-by-one error in my transmit function was loving things up :argh:

Dijkstracula fucked around with this message at 00:32 on May 2, 2009

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Free Bees posted:

Visual Studio owns.
Pretty much this. It took me about half an hour to get as proficient with the VS debugger as I was with gdb after like a month.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

I don't think they're talking about functionality so much as the intuitiveness of VS' debugger. In general, debuggers that are built into IDEs are easier for the neophyte to pick up - think about setting a breakpoint in Eclipse as compared to gdb, for instance. Once you know a bit about the latter there's nothing to it, but it seems a bit more arcane than clicking a tab to the left of the line you want a break on.

tripwire posted:

Python is interpreted and comes with an interactive shell.
This seems unrelated to what they're talking about :confused:

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Ah, that's a good point; I suppose instead of inspecting your data in a debugger, you could quite literally just print it out in the intepreter :) I hadn't really thought about things that way.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Avenging Dentist posted:

Apparently we're getting better at this!
Or worse - before, we'd get a page of comedy as a result. :(

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

The only one that comes to mind for me is hexadecimal getting banned, and I think that happened outside SH/SC anyway.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

tef posted:

And yes, hexadecimal (perma'd user enenthogen)
Oh really? I missed that memo. Given the wrath he generated with his posts, I guess he really should be crowned as Best SH/SC Troll.

:patriot: !(x ^ y) :patriot:

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

royallthefourth posted:

Prolog is really just a relational database, like SQL. You wouldn't write a whole app in SQL, and doing so in Prolog is also a really bad idea. But when you need it, it's really great.

Also, dynamic programming/memoization might solve this problem.
Wait, wait, what? What the hell are you talking about? Prolog is a logic language and has nothing to do with databases. Also, how would DP possibly help solving this problem? Sounds to me like you're just throwing around words.

Yes, this is a nice constraint satisfaction problem, so Prolog would do the job well. Five bucks says tef has already seen this thread and is working on a solution right now :v:

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

tef posted:

Datalog is an example to the contrary - logical programming makes it very easy to express the relationship between things.
True, I'll grant you that, but you can't honestly claim that resolution is equivalent to a SQL query. edit: which I believe was his intention.

Dijkstracula fucked around with this message at 19:16 on Jun 4, 2009

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Evil Home Stereo posted:

I don't really understand why it is possible to solve this type of problem in some languages and not others.
It's not a matter of whether it's possible; as quadreb mentioned, an implication of two languages being Turing complete is that any algorithm* you can implement in one can be implemented in another. However, the nature of different languages makes certain kinds of problems far easier to do in some than in others. For instance, your problem is a good example of a constraint satisfaction problem (as tef pointed out, minimizing the V() function throws a wrench into the works, but otherwise it's a straightforward one). You can solve CSPs in any language; however, logic languages like Prolog were in some sense designed to solve this sort of problem, so the syntax and the back-end of the language makes solving these problems very straightforward. Of course you can do it in Java; look into a CSP library like this one if you like. Or, roll your own. :)

*algorithm isn't quite the right word; the technical term is "computable function", which has different implications, which delves into a bit more CS theory than you probably care about at this point.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

ShoulderDaemon posted:

Aho, Sethi, and Ullman's book is generally considered to be a strong introductory and reference text.
If you want the K&R of compiler design texts, this is the one. It doesn't gently caress around and is pretty intense.

You may want to pair it with a text on language theory such as the Sipser or the Ullman / Hopcroft, as the Dragon book drops you in the deep end with respect to grammars and whatnot.

It'd be fun to start up a reading group for the Dragon text. I really hope I get to TA the compiler class next year :)

Dijkstracula fucked around with this message at 00:17 on Jun 18, 2009

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

DRO posted:

I'm writing a program in MIPS and I'm having a problem formatting output.

More specifically, I need to take an integer and put a decimal to the left of the the right-most character. (ie: the integer stored in the register is 2003 and I need it to print 200.3 ) How do I get the output to format like that?

Hopefully somebody can help me out with this.
I assume you mean MIPS assembly? OK, here's a hint: if you perform integer division on 2003 by 10, what do you get? How can you use this to print the rest of "200.3"?

(Also this sounds suspiciously like part of a homework problem.)

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

sund posted:

Just making sure that you didn't do x-((x/10)*10) to get the decimal place. I'm not familiar with MIPS assembly, but by a quick google search it looks like the divide instruction performs a modulo operation as well, so you only have to do a single math instruction.
Well, it's assembly, so you can't nest operations like that anyway. But yes, division also storing the remainder sounds right (it's been a few years since my assembly classes)

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

outlier posted:

A graph layout / graphics type problem: I've written some code to draw phylogenetic trees, but I developed it from first principles, it's subpar and I'd like some pointers to decent prior art or algorithms.

Here are two programs for phylogeny viz I've seen others using.

http://www.phylowidget.org/
http://loco.biosci.arizona.edu/paloverde/paloverde.html

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

I don't know the name of such a thing, but why on earth would you want to use that instead of a bit field? Suddenly extracting values becomes Hard-With-A-Capitol-H rather than a simple mask and shift.

Dijkstracula fucked around with this message at 18:50 on Aug 1, 2009

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

nbv4 posted:

Instead of creating a table in my database with a bunch of boolean columns, I can store all the information in one bigint. This way if I want to add a new boolean, instead of creating a new column in my table, I can just factor in a new prime. The only problem is that it would probably overflow the integer after so many primes...
:psyduck: I'm astonished that this is your solution to this problem. I mean, I hate to perpetuate a sense of elitism in CoC and everything, but I strongly recommend you look at properties of the binary number system before implementing this idea.

nbv4 posted:

The method I remember reading about may have used addition, because I remember it being used with like 40 different booleans.
Go and read the fundamental theorem of arithmetic and tell me if you think a sum of primes works the same was as a product of primes (hint: 2,3,5 are prime. if 2+3 = 5, what does this mean about the uniqueness of a decomposition of a sum of primes?). Also, you remember it wrong.


edit: or, I'm easily trolled? :confused:

Dijkstracula fucked around with this message at 21:26 on Aug 1, 2009

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Garbled, how? Is it a formatting issue (ie. correct characters not in the expected place) or are even the characters completely off? What are the differences between the computers that poo poo the bed and the ones that don't In any event, without seeing code, it's hard to tell what the issue is. Maybe post the contents of your SIGWINCH handler?

also, "putty" is not a terminal type, so ncurses doesn't know anything about it.

edit: I just reread your post.

Chuu posted:

All I'm doing is when data is pumped in, I check the height/width of the terminal, and put text on the screen based on that. I'm not doing anything fancy with events, all my code is based on the height/width global variables.
That you're handling window resize operations in a bizzare way might be the cause of your program doing strange things when you try to resize the window, maybe? :confused:

In any event, post the relevant code, look up Unix signals, and implement a SIGWINCH handler. Even if this isn't the cause of your problems, you'll be one step closer to having a reasonably-well written program.

Dijkstracula fucked around with this message at 14:44 on Sep 5, 2009

Adbot
ADBOT LOVES YOU

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

There's nothing wrong with semi-modern Fortran standards. Yes, Fortran 77 is pretty drat archaic, but if you updated the code to Fortran 90/95 standards, then you'll have far more readable and modern code without having to rewrite the entire thing from scratch.

But, I'm not convinced porting code is the best way to learn a language, especially between languages like C and Fortran. I'm envisioning a post a few months from now where he asks "my C code is so much slower wtf" and us discovering that he didn't take into account Fortran's column-major arrays vs. C's row-major arrays and ended up blowing his cache or something. In my opinion it's better to work with what you know and save the "learn a language" projects for when they're not critical to your research/job/etc.

Dijkstracula fucked around with this message at 20:45 on Oct 18, 2009

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