• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

Quasar

Member
So I have a Linq ro SQL question.

I have this LINQ query.

Code:
(from a in Nurses 
 join w in Wards on a.NurseWardAssigned equals w.WardID 
 group w by w.WardName into nursesCount
 
 select new
          {
           WardAssigned = nursesCount.Key,
           NumberNurses = nursesCount.Count()
          });

Which works. Just that for rows where the count is 0 the row is not returned at all.

How would I get it to return a row with 0 as the count value?
 

maeh2k

Member
So I have a Linq ro SQL question.

I have this LINQ query.

Code:
(from a in Nurses 
 join w in Wards on a.NurseWardAssigned equals w.WardID 
 group w by w.WardName into nursesCount
 
 select new
          {
           WardAssigned = nursesCount.Key,
           NumberProducts = nursesCount.Count()
          });

Which works. Just that for rows where the count is 0 the row is not returned at all.

How would I get it to return a row with 0 as the count value?

Use an outer join like this: http://msdn.microsoft.com/en-us/library/bb397895.aspx
 

Atruvius

Member
There should be an event that fires when the user selects something from the ComboBox. I believe it's SelectIndexChanged. Create one of those for both ComboBoxes and then check in the event method if the other one has something selected as well. If yes, enable the button. This doesn't scale super well for more than two ComboBoxes, but for two it should be fine.

I checked out Timer and that kind of works like Unity's Update function as you can set how frequently it updates. Didn't need to use it for ComboBoxes though.

Completed my little program this morning. It probably took longer than it should but I hadn't used Forms stuff in a while. The program lets user choose what time Windows should shut down since I was annoyed this basic feature wasn't shipped with Windows.
 

hateradio

The Most Dangerous Yes Man
I tried something like that:

Code:
NumberNurses = (nurseCount.Count() == 0 ? 0: nurseCount.Count())
But still for the rows where its 0 the row isn't returned.
What you're doing is something like this.

number == 0 ? 0 : number . . . which is really just number.

Your query is the issue.
 
So, for fun, I wrote a CHIP-8 emulator yesterday in Java.

(Technically, it's an interpreter, not an emulator, but still.)

CHIP-8 is actually a rather easy and simple system to interpret, and I kind of randomly decided that yesterday was the day to do it. It's almost complete, but 1) I didn't implement input yet, and 2) one or two programs might have glitches (but I'm not actually sure because I didn't try them in another emulator).

The hardest part of the whole thing was actually getting around Java's stupid signed variables. I didn't realize that if a byte is negative (0x80 or larger in unsigned terms), then casting to a larger data type like short or int will fill the new bits with 1s instead of 0s... Caused many problems when writing code like opcode = memory[pc] << 8 | memory[pc+1].

If anyone decides to create a CHIP-8 interpreter, I suggest starting with the program called Maze, as it is only 30 bytes large at best and only uses six or seven unique opcodes.

For some background info on the CHIP-8, it is a virtual machine with the following specs:
RAM: 4 KB RAM (minus 768 bytes for screen and other data)
Screen: 64x32 monochrome screen. Drawing to the screen is done with sprites only.
Input: 6-key controller / keyboard.
CPU: 8-bit with 16-bit opcodes, 16 general purpose registers, 2 timers, and a 12-bit special register for storing memory addresses


I have a few questions, though...

1) Does anyone have good ideas of any CHIP-8 programs or games that really test the system?
2) Any ideas of another (preferably real) system to try writing an emulator for? I'd prefer something with simple graphics output.
 

Sharp

Member
The virtue of undefined behavior is that a language implementor can use that flexibility to make things more efficient than might be possible otherwise. For instance, a C's function call can evaluate its arguments in any order, so a compiler author can just pick whatever order happens to be fastest.
No, you're thinking of implementation-defined behavior. Undefined behavior means anything can happen, because the compiler assumes it does not happen, like doing pointer arithmetic that leaves a pointer more than one byte past the end of allocated memory. If undefined behavior is ever invoked by your program, it's not valid.
 

Lem

Neo Member
So I recently started learning SML and I have some problems with that language...

I want to check if a list of strings contains a given string and return the whole list containing everything except the given string (it has to return SOME list). So for example: f ( "hello", ["hi", "hello", "welcome"] returns ["hi", "welcome"]. So my idea looks like this:

Code:
fun test(x : string, xs : string list) =
let
    val zs = [] // I bind a empty list
in
    case xs of
	[] => NONE // if the given string list is empty then I return NONE, since its empty
      | y::ys =>  // if the given list is not empty I proceed
	case same_string (x, y) of // this function return true if x and y are the same
	    true => SOME (zs @ ys) // if true then I return the tail of the list appended with zs 
	  | false => test (x, ys) // i recursively call test but here is the problem... 
I need to add the y value to zs but dont know how to do it... i try something like true => SOME (y::zs @ test (x, ys)) but then the expressions dont match and I get errors :/
since string list option is not the same as string list
end

Any ideas guys how to fix it?
 

poweld

Member
So I recently started learning SML and I have some problems with that language...

I want to check if a list of strings contains a given string and return the whole list containing everything except the given string (it has to return SOME list). So for example: f ( "hello", ["hi", "hello", "welcome"] returns ["hi", "welcome"]. So my idea looks like this:

Code:
fun test(x : string, xs : string list) =
let
    val zs = [] // I bind a empty list
in
    case xs of
	[] => NONE // if the given string list is empty then I return NONE, since its empty
      | y::ys =>  // if the given list is not empty I proceed
	case same_string (x, y) of // this function return true if x and y are the same
	    true => SOME (zs @ ys) // if true then I return the tail of the list appended with zs 
	  | false => test (x, ys) // i recursively call test but here is the problem... 
I need to add the y value to zs but dont know how to do it... i try something like true => SOME (y::zs @ test (x, ys)) but then the expressions dont match and I get errors :/
since string list option is not the same as string list
end

Any ideas guys how to fix it?
Code:
fun removeStringHelper (stringToRemove: string, strings: string list, acc: string list option) =                                       
  case strings of                                                                                                                      
    [] => acc |                                                                                                                        
    head :: tail =>                                                                                                                    
      case same_string(stringToRemove, head) of                                                                                        
        true => removeStringHelper(stringToRemove, tail, acc) |                                                                        
        false => removeStringHelper(stringToRemove, tail, SOME(getOpt(acc, []) @ [head]))                                              
                                                                                                                                       
fun removeString (stringToRemove: string, strings: string list) : string list option =                                               
  removeStringHelper(stringToRemove, strings, NONE)

Slight optimization by using tail recursion. The idea is to only append each string to the accumulator if it does not match the string you're trying to remove.

So, in the case of a match, simply call the helper function with the current contents of the accumulator, throwing away the current string (head).

In the case of a mismatch, we want to append the string to the accumulator. Since the accumulator is an option, we use getOpt to get the string list if it is SOME, or the empty list if it is NONE, and append the string to the result.
 

tuffy

Member
No, you're thinking of implementation-defined behavior. Undefined behavior means anything can happen, because the compiler assumes it does not happen, like doing pointer arithmetic that leaves a pointer more than one byte past the end of allocated memory. If undefined behavior is ever invoked by your program, it's not valid.
The compiler does assume things with undefined behavior happen, but the spec imposes no requirements on how to handle them. Things like integer overflow and
Code:
i = ++i + 1;
are undefined, but your program isn't likely to blow up if you use them.

The evaluation of function arguments is actually unspecified behavior rather than implementation-defined, however.

But my point is that having that fuzziness in the specification allow for easier implementation and better optimization than might be possible otherwise.
 

Lem

Neo Member
@poweld
Thanks man! That works just great! Really appreciate your help, I tried to figure out how to fix the problem for a whole day and nothing came to my mind... also I didnt know the getOpt function :/
 

Sharp

Member
The compiler does assume things with undefined behavior happen, but the spec imposes no requirements on how to handle them. Things like integer overflow and
Code:
i = ++i + 1;
are undefined, but your program isn't likely to blow up if you use them.

The evaluation of function arguments is actually unspecified behavior rather than implementation-defined, however.

But my point is that having that fuzziness in the specification allow for easier implementation and better optimization than might be possible otherwise.
Actually, when compilers did start treating integer overflow as undefined instead of just wrapping, programs did blow up. People are very reliant on the behavior of current implementations. That's why I always view this argument with skepticism: I understand it in the abstract, but wherever it is actually applied in the real world people complain.

(And no, having read what you wrote more carefully: the compiler does not, or rather does not have to, assume that undefined behavior occurs. Please read http://blog.regehr.org/archives/213).
 

tuffy

Member
Actually, when compilers did start treating integer overflow as undefined instead of just wrapping, programs did blow up. People are very reliant on the behavior of current implementations. That's why I always view this argument with skepticism: I understand it in the abstract, but wherever it is actually applied in the real world people complain.
So you believe C implementations could be more efficient if compilers were required to implement the many undefined parts of the spec in a certain way? Which parts of the spec do you believe could be implemented faster on every platform if they were more rigidly defined? And do you have any evidence of this superiority of a more well-defined spec?

Literally nobody is arguing that C programmers should rely on undefined behavior.
(And no, having read what you wrote more carefully: the compiler does not, or rather does not have to, assume that undefined behavior occurs. Please read http://blog.regehr.org/archives/213).
The compiler has to generate code to do something if the program is syntactically valid, even if the behavior of that code is undefined. It can't "assume that it never occurs", as you say. Sometimes that something is to crash. Sometimes it's to behave in some platform-specific way. Programmers should not rely on that behavior. But I still assert that a compiler author's flexibility to choose how behave in those instances allows for more efficient implementations, even if that means shifting more of the burden for avoiding undefined behavior to the end programmer.
 

Sharp

Member
So you believe C implementations could be more efficient if compilers were required to implement the many undefined parts of the spec in a certain way? Which parts of the spec do you believe could be implemented faster on every platform if they were more rigidly defined? And do you have any evidence of this superiority of a more well-defined spec?
I don't think they could be more efficient. I think they would be safer and more sane. And the author of the post I linked has indeed proposed a variant of C that cuts out the undefined behavior, which as he put it is the version of C that people think exists anyway. As for "superiority," from a safety perspective I think Java demonstrates that it can indeed be superior to have a well-defined spec. For that matter, I think Rust is demonstrating that you can still have C++-like performance by making it impossible to *write* the undefined behavior, instead of just removing it entirely.
Literally nobody is arguing that C programmers should rely on undefined behavior.
I am not accusing you of saying that.
The compiler has to generate code to do something if the program is syntactically valid, even if the behavior of that code is undefined. It can't "assume that it never occurs", as you say. Sometimes that something is to crash. Sometimes it's to behave in some platform-specific way. Programmers should not rely on that behavior. But I still assert that a compiler author's flexibility to choose how behave in those instances allows for more efficient implementations, even if that means shifting more of the burden for avoiding undefined behavior to the end programmer.
Usually, compilers can't check whether you're actually producing undefined behavior or not. For example, when you perform signed integer arithmetic, they don't know whether you've verified in advance that it can't overflow. When you dereference a pointer, they can't verify in advance that it won't be null. When you use a float pointer and a double pointer, they can't verify that the two will never alias. But they can generate code assuming it doesn't happen, and not worry at all about the behavior if that assumption is violated. This can lead to much worse than crashes. If you really want to see fun undefined behavior, look at some of the register load orders compilers will set up if you don't use appropriate fences and barriers in a multithreaded environment.
 

Quasar

Member
Have you tried it with 'null'?

Yeah.

I refined my query to:

Code:
            var query = (from w in db.Wards
                         join n in db.Nurses on w.wardID equals n.nurseWardAssigned into nGroup
                         from sub in nGroup.DefaultIfEmpty()
                         group w by w.wardName into nurseCount
                         select new
                         {
                             name = nurseCount.Key,
                             count = (nurseCount.Count() == null ? 0 : nurseCount.Count())
                         });

But that does not return the right results. In places where it should return 0 as count its returning 1 instead.

Ideas?
 

Tristam

Member
Does anyone know how to add auto-generated class files from a T4 template to a VS project as part of the build process? I also want to generate the files at build time but figured out how to do that using the TextTransform.exe command line tool. Just generating them isn't enough, though--they also need to be added to the project in order for the project to know they exist and therefore build properly.
 

Slavik81

Member
Doesn't that essentially say 'if number is 0 then return 0 otherwise return number'?
Yes, unless there's some magic going on:

Code:
return number == 0 ? 0 : number;
is the same as:
Code:
if (number == 0)
  return 0;
else 
  return number;
is the same as:
Code:
if (number == 0)
  return number;
else 
  return number;
is the same as:
Code:
return number;
 

Slavik81

Member
Any idea why I'm not seeing any differences when turning off TrueType bytecode font-hinting? I've patched libfreetype like so:

Code:
--- freetype-2.5.2-orig/include/config/ftoption.h	2014-10-19 18:52:58.203194931 -0600
+++ freetype-2.5.2/include/config/ftoption.h	2014-10-19 18:52:55.479194969 -0600
@@ -570,6 +570,7 @@
   /*   define it for certain configurations only.                          */
   /*                                                                       */
 #define TT_CONFIG_OPTION_BYTECODE_INTERPRETER
+#undef TT_CONFIG_OPTION_BYTECODE_INTERPRETER 
 
 
   /*************************************************************************/

Then preloaded my custom *.so
Code:
LD_PRELOAD=/home/slavik/ws/freetype/freetype-2.5.2/freetype-2.5.2/bytecode/.libs/libfreetype.so gedit -s &

Yet it still looks identical. Even with tiny fonts.
 

Husker86

Member
One of the threads about programming that popped up a while back mentions stacksocial.com...oh boy.

I've started a couple of courses on Udemy but I am drowning in ones that I haven't started. I feel like a gamer who buys games only to add them to their backlog. There needs to be more hours in a day.
 

Mathaou

legacy of cane
I am really stuck, I'm doing my homework and I need to create a program that prints out a diamond of an amount of rows that the user specifies. I already made a diamond program in a previous problem, but I don't know how to. I'm really stuck, can someone just explain to me some logic that would help me now as well as in the future?

I need hints, don't just fix my code:
Code:
public class Diamond {
  public static void main(String[] args) {
    for (int i = 1; i < 10; i += 2) {
      for (int j = 0; j < 9 - i / 2; j++)
        System.out.print(" ");

      for (int j = 0; j < i; j++)
        System.out.print("*");

      System.out.print("\n");
    }

    for (int i = 7; i > 0; i -= 2) {
      for (int j = 0; j < 9 - i / 2; j++)
        System.out.print(" ");

      for (int j = 0; j < i; j++)
        System.out.print("*");

      System.out.print("\n");
    }
  }
}
 
i have been working on this project for the better part of the week and i about to lose my mind. I am supposed to write a lexical analyzer for HTML in c++

The rules are something like this:

TEXT – any characters outside of angle brackets
• LANGLE – a left angle bracket character
• RANGLE – a right angle bracket character
• SLASH – a / character
• ID – an identifier, defined to be a sequence that begins with a letter and is followed by zero or more
letters, digits, periods, or hyphens
• EQ – an equals sign character
• QSTRING – a quoted string, defined as a “ followed by zero or more characters, followed by a “, all on
the same line
• OTHER – anything else
• END – an end of file or error condition


So for this syntax, the HTML sequence:

Hello there <H1 style=”BOLD”>header!!</H1>

Would be recognized as the sequence of tokens:
TEXT, LANGLE, ID, ID, EQ, QSTRING, RANGLE, TEXT, LANGLE, SLASH, ID, RANGLE

I have plenty of hurdles/problems/shit stains to get rid of in the project, as they are MANY other requirements. but right now i am struggling on how to keep track of where text ends so i can make make token for text. May be i can read the sequence character by character and make a substring of everything till < and after >. Sometimes it sounds more complex and almost impossible, sometimes i feel like i am an idiot and a simple structured loops will solve the problem.

Two days of caffeine and no sleep has fried my brain, so help me out here guys if possible.

ANY abstract code would be helpful, i just need some direction so i can get working again.
 

tokkun

Member
i have been working on this project for the better part of the week and i about to lose my mind. I am supposed to write a lexical analyzer for HTML in c++

The rules are something like this:

TEXT &#8211; any characters outside of angle brackets
&#8226; LANGLE &#8211; a left angle bracket character
&#8226; RANGLE &#8211; a right angle bracket character
&#8226; SLASH &#8211; a / character
&#8226; ID &#8211; an identifier, defined to be a sequence that begins with a letter and is followed by zero or more
letters, digits, periods, or hyphens
&#8226; EQ &#8211; an equals sign character
&#8226; QSTRING &#8211; a quoted string, defined as a &#8220; followed by zero or more characters, followed by a &#8220;, all on
the same line
&#8226; OTHER &#8211; anything else
&#8226; END &#8211; an end of file or error condition


So for this syntax, the HTML sequence:

Hello there <H1 style=&#8221;BOLD&#8221;>header!!</H1>

Would be recognized as the sequence of tokens:
TEXT, LANGLE, ID, ID, EQ, QSTRING, RANGLE, TEXT, LANGLE, SLASH, ID, RANGLE

I have plenty of hurdles/problems/shit stains to get rid of in the project, as they are MANY other requirements. but right now i am struggling on how to keep track of where text ends so i can make make token for text. May be i can read the sequence character by character and make a substring of everything till < and after >. Sometimes it sounds more complex and almost impossible, sometimes i feel like i am an idiot and a simple structured loops will solve the problem.

Two days of caffeine and no sleep has fried my brain, so help me out here guys if possible.

ANY abstract code would be helpful, i just need some direction so i can get working again.

I wrote a lexer/parser for the Verilog language a few months ago. I had to go through a couple revisions before I found a design structure that worked. Because HTML is a context-free language you need to use a stack when parsing the language. There are two options: (1) Use a stack explicitly, and push/pop tags or (2) let the compiler create the stack for you by using recursion. I suggest doing the latter. Here's my general advice for approaching the problem.

1. Start by writing the grammar rules for HTML. This is not code, it's just a description of the things that you need to parse in a valid document. Start by describing it in the most general sense, and get more specific. You have a general sense of this in your example, but you need to start from a higher level of abstraction. For instance, what makes up a valid HTML document? A set of html tags surrounding a header, a body, maybe some other stuff. What makes up a header? Header tags surrounding some other tagged items? What makes up a tagged item?...You get the picture. Be sure to be clear about what is required and what is optional in each rule.

2. Write a function for each rule that takes a string and tries to consume a token from the start of the string that obeys the rule. For instance, for the HTML rule, you would try to consume an HTML opening tag, a header section, a body section, and an html closing tag.

I used a signature that looked like this:

Code:
string ConsumeRule(const string& input, string* token);

and had the function store the parsed rule in 'token' and return the remainder of the string (minus the parsed token). Within the function, you call the Consume subrules needed to satisfy the rule. You will also want to be able to do things like throw exceptions if you are unable to parse a token according to the rule. Then you can use try/catch blocks to deal with optional parts of rules.

The nice thing about this recursive approach is that you can keep each rule function relatively simple and modular, so it is easier to understand and test.
 

Apoc29

Member
I am really stuck, I'm doing my homework and I need to create a program that prints out a diamond of an amount of rows that the user specifies. I already made a diamond program in a previous problem, but I don't know how to. I'm really stuck, can someone just explain to me some logic that would help me now as well as in the future?

I need hints, don't just fix my code:

If the problem doesn't forbid it, I would consider building your string using StringBuilder, rather than trying to output everything in sequence. Create a StringBuilder object and append strings to it and output everything at the end using its toString() method.

If the diamond is symmetrical, don't bother building both the top and bottom; build one or the other, store each line in an array of strings or something, then iterate backwards through the array to build the other half.
 

Chris R

Member
I am really stuck, I'm doing my homework and I need to create a program that prints out a diamond of an amount of rows that the user specifies. I already made a diamond program in a previous problem, but I don't know how to. I'm really stuck, can someone just explain to me some logic that would help me now as well as in the future?

Your 10s, 9s and 7s need to be replaced. If your user inputs a value X, then what would that transform 10 into? What about 9? Store the value the user gives you in a variable and work with that to properly display the diamond. The only issue I could see you having is if you have an even number to deal with, as one less row needs to be displayed.

Yes, you could probably use a stringbuilder to make things "easier" but that would be a bunch of work when you are close to an answer now with the code you posted.
 

spootime

Member
Hey guys. I'm finishing up my bio degree in the next year (currently a senior) and I've been seriously considering making a jump over to CS. My reasoning is that I've really enjoyed the little programming I've done through sites like codeacademy and coursera and I really have no desire to pursue a masters or phd in biology. My question is this: in my case, where I have basically no prereqs for CS completed besides general stuff like math and physics, would it make sense to get a masters in comp sci or just try to get another B.S in CS? My ultimate goal being to get into the games industry.
 

BreakyBoy

o_O @_@ O_o
Hey guys. I'm finishing up my bio degree in the next year (currently a senior) and I've been seriously considering making a jump over to CS. My reasoning is that I've really enjoyed the little programming I've done through sites like codeacademy and coursera and I really have no desire to pursue a masters or phd in biology. My question is this: in my case, where I have basically no prereqs for CS completed besides general stuff like math and physics, would it make sense to get a masters in comp sci or just try to get another B.S in CS? My ultimate goal being to get into the games industry.

Some of the actual college grads here could probably be of better help, but if you've got the math & science pre-reqs down, I would just go for the masters if I were you.

That's a big if though. I'm not too familiar with the usual Bio major math reqs, but CompSci often requires things like Discrete Maths. Either way, if I were you, I'd sit down with some admin from your School of Engineering and explore your options.
 

spootime

Member
Some of the actual college grads here could probably be of better help, but if you've got the math & science pre-reqs down, I would just go for the masters if I were you.

That's a big if though. I'm not too familiar with the usual Bio major math reqs, but CompSci often requires things like Discrete Maths. Either way, if I were you, I'd sit down with some admin from your School of Engineering and explore your options.

I've taken two basic physics and calculus 1 and 2. I could probably pick up linear algebra or discrete before I finish my degree.

My basic dilemma is that I'm gonna probably have to take around two semesters worth of pre-reqs to get into a masters program from what I've seen. At that point - do I just go for the BS??
 

hateradio

The Most Dangerous Yes Man
My question is this: in my case, where I have basically no prereqs for CS completed besides general stuff like math and physics, would it make sense to get a masters in comp sci or just try to get another B.S in CS? My ultimate goal being to get into the games industry.
There are some schools that do not require a BS in CS to get a MS in CS. If you've taken a few CS classes that will help so that they can transfer the units over.

I'm currently in one of those schools, but they do have you take some pre-reqs if you don't have them, which can increase your expected graduation time. Mine is about three years total if I keep doing it full time (with some variation in the last two quarters).
 

tokkun

Member
Hey guys. I'm finishing up my bio degree in the next year (currently a senior) and I've been seriously considering making a jump over to CS. My reasoning is that I've really enjoyed the little programming I've done through sites like codeacademy and coursera and I really have no desire to pursue a masters or phd in biology. My question is this: in my case, where I have basically no prereqs for CS completed besides general stuff like math and physics, would it make sense to get a masters in comp sci or just try to get another B.S in CS? My ultimate goal being to get into the games industry.

You could combine your biology degree with programming by doing an MS with someone in the Computational Biology / Bioinformatics / Synthetic Biology field. Seems like that will be a much better job market over the next decade than the games industry. Of course if being a games programmer is your dream job or something, then maybe that doesn't matter to you.
 

spootime

Member
There are some schools that do not require a BS in CS to get a MS in CS. If you've taken a few CS classes that will help so that they can transfer the units over.

I'm currently in one of those schools, but they do have you take some pre-reqs if you don't have them, which can increase your expected graduation time. Mine is about three years total if I keep doing it full time (with some variation in the last two quarters).

Looking at the pre-reqs I would have to take, it seems like my grad time would be about the same. I currently go to nc state which has a pretty good CS department, so I'll definitely be checking with them to see how lenient they are on admitting someone and then letting them finish up prereqs.

You could combine your biology degree with programming by doing an MS with someone in the Computational Biology / Bioinformatics / Synthetic Biology field. Seems like that will be a much better job market over the next decade than the games industry. Of course if being a games programmer is your dream job or something, then maybe that doesn't matter to you.

I was considering this as well. I'm just not sure I have a passion for continuing biology any further. I wouldn't be averse to working outside the games industry but I would prefer it not be in biology. That said it is definitely on my mind.

One thing I haven't been able to find much data on so far is how much GPA and GRE score matter for CS masters programs. Anyone have any insight on this? My gpa isnt stellar (3.3-3.4 depending on how hard biochem crushes me next semester) but I'm fairly confident I would crush the GRE based on my previous experience with standardized tests like the lsat.

Thanks for the responses guys, I appreciate it.
 

hateradio

The Most Dangerous Yes Man
Some universities do not require a GRE, but it all depends on the school. It's probably not as important, besides the math portion probably.
 

Anustart

Member
Say I have a vector of vectors in c++. I'm needing to use an auto iterator to go through these for displaying the data. I accomplished that no problem, but I'm needing a line break after the end of each of the inner vectors, and I don't know how to accomplish this.

Code:
for (auto& it : paragraph)
  {
    for (auto& itTwo : it)
    {
      cout << itTwo << " ";
    }
  }

paragraph is the container of the individual vectors. I'm needing a line break after itTwo reaches the end of each of the inner vectors.
 

Slavik81

Member
Say I have a vector of vectors in c++. I'm needing to use an auto iterator to go through these for displaying the data. I accomplished that no problem, but I'm needing a line break after the end of each of the inner vectors, and I don't know how to accomplish this.

Code:
for (auto& it : paragraph)
  {
    for (auto& itTwo : it)
    {
      cout << itTwo << " ";
    }
  }

paragraph is the container of the individual vectors. I'm needing a line break after itTwo reaches the end of each of the inner vectors.
Then put it after the end of the itTwo loop.

One way of thinking about this is to think about how often you want something to happen, and how often the loop will be run. You want your newline output to be once per vector. The inner loop runs once per item in each vector, which is too frequent. The outer loop, however, runs once per vector, so that's where it should go.

By the way, consider using better variable names. 'it' would be better named 'line' or 'sentence' or whatever it is. itTwo would be better named 'word' or whatever it is. The reasoning I suggest in my previous paragraph also becomes easier with better names. e.g. you can more clearly see where you need to do things once per word when each word gets put in a variable named 'word'.

Finally, I should mention that the current names are particularly bad because 'it' is typically used as a variable name for iterators, but those variables are not iterators. With that style of for loop, the iterators are hidden behind the scenes. The for statement there just gives you each item in the container.
 

RiggyRob

Member
Little off-topic, but is there a Unity-specific thread on NeoGAF? I'm having a crack at making my own game and I was wondering if there was a thread with useful resources/active users that I can ask questions.
 
Just about 6 months until I finish my BS in Computer Science...feel like I've been in school forever, but excited to almost be done.

I think the state of CS education at my university could definitely be much better. But I have had some good classes for sure, and definitely think I'm a better programmer for getting the degree.
 

tokkun

Member
I was considering this as well. I'm just not sure I have a passion for continuing biology any further. I wouldn't be averse to working outside the games industry but I would prefer it not be in biology. That said it is definitely on my mind.

Fair enough. I wouldn't council going into it if you are sure you will not enjoy it. I would encourage you to fully explore what it means to be in bioinformatics. You may find that in some cases it is really a CS job in terms of what you do, but one where knowledge of biology is seen as valuable. If I were in your place, I would be thinking "Is there a way I can use my biology degree as a competitive advantage to get a CS job?"

One thing I haven't been able to find much data on so far is how much GPA and GRE score matter for CS masters programs. Anyone have any insight on this? My gpa isnt stellar (3.3-3.4 depending on how hard biochem crushes me next semester) but I'm fairly confident I would crush the GRE based on my previous experience with standardized tests like the lsat.

It depends on the school and program. Are you looking to get into a highly ranked, highly competitive CS program? What I've discovered from talking with people in admissions in competitive programs is that GPA and GRE scores are used as more of a first-level filter on applicants. So if your scores are poor (based on their standard of 'poor'), you may get rejected before they take a look at the rest of the application. Now given that your BS is in a different area, they might be more likely to put weight on the GRE. And there is a CS Subject GRE, which gives non-CS students a chance to demonstrate that they are good at CS.

That is just the front door into grad school, though. You should also consider the back door (getting a professor in the department to support you application) and side door (getting admitted to a less competitive department at the same university, then switching departments after a year). These are viable approaches for people who might otherwise get rejected based on GRE or GPA.

You should probably also give some thought to how you would explain your shift from biology to CS directly out of school. For someone with a biology degree looking to go into Bioinformatics, I would think "Oh, this is a forward-looking person trying to get into a hot field that requires multidisciplinary study." For someone looking to get into the video game industry, it feels more like - no offense intended - a flaky person who didn't think through their original major and thinks that a CS degree will be like playing games for a living.
 

Slavik81

Member
Hey guys. I'm finishing up my bio degree in the next year (currently a senior) and I've been seriously considering making a jump over to CS. My reasoning is that I've really enjoyed the little programming I've done through sites like codeacademy and coursera and I really have no desire to pursue a masters or phd in biology. My question is this: in my case, where I have basically no prereqs for CS completed besides general stuff like math and physics, would it make sense to get a masters in comp sci or just try to get another B.S in CS? My ultimate goal being to get into the games industry.

There's actually some pretty sweet crossovers between biology and computer science. I have no background in biology myself, but am doing my masters with the biological modeling and visualization research group at the University of Calgary. In part, I chose this path because I like games and I think I'll learn quite a lot about procedural modelling and general computer graphics. In particular, I think it's a good step towards building tools like SpeedTree.

With that being said, I'm not sure the biology background would be as valuable in games as it is to our sort of research. You have a big hill to climb in learning all the things needed to be technically proficient for game development. It's doable, but I don't think there's a fast way of getting there. It's going to take years to build those skills no matter what.

I will say this, though. Going for another B.Sc. in Computer Science seems insane to me. It's a far safer path to leverage what you already have into a cross-disciplinary masters / job, and move steadily into more CS-focused roles.
 

mooooose

Member
Hey working on a project in Java that will require a graph data structure. I don't have tons of experience with graphs in programming, so I was wondering what would be the best way to implement this? Is there a good standard Java API? Because I've had trouble finding one, if there is. Should I just make my own?

It's for a map based games where nodes have varying degrees from 2 to 5.
 

Anustart

Member
Then put it after the end of the itTwo loop.

One way of thinking about this is to think about how often you want something to happen, and how often the loop will be run. You want your newline output to be once per vector. The inner loop runs once per item in each vector, which is too frequent. The outer loop, however, runs once per vector, so that's where it should go.

By the way, consider using better variable names. 'it' would be better named 'line' or 'sentence' or whatever it is. itTwo would be better named 'word' or whatever it is. The reasoning I suggest in my previous paragraph also becomes easier with better names. e.g. you can more clearly see where you need to do things once per word when each word gets put in a variable named 'word'.

Finally, I should mention that the current names are particularly bad because 'it' is typically used as a variable name for iterators, but those variables are not iterators. With that style of for loop, the iterators are hidden behind the scenes. The for statement there just gives you each item in the container.

Thank you very much for the good information all around. I didn't even know those weren't iterators themselves! And the naming scheme makes a lot of sense.
 
Yeah Randdalf is right, define is a special form that has 2 versions:

Code:
(define (f arg1 arg2 arg3 ...) (do stuff))

Which will bind the identifier "f" to a procedure with arguments named for the rest of the list parameters and:

Code:
(define x 2)

Which will bind the identifier "x" to the value given (2 in this case).
 
Top Bottom