• 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

He asked for an OOP language. C# is relevant, has a big community (meaning plenty of help and examples, same for Java though), plus you get to use God's IDE with the beauty that is Entity Framework/Linq. I love Java as well, but C# is my darling.

Curly braces should belong on a newline, as it makes the code cleaner imo. As for annoyances, Java makes you spell it out way too often. class foo extends foobar implements whatever, too verbose. C# is guilty of this at times, but Java seems worse.

Amen to that brother.
C# is like C++ only managed haven't worked with it for like 2 years but it had more features then java but less built in data structures if i remembered it right could have changed in those 2 years.

Tab 4 spaces or 8 spaces?
 

Magni

Member
Amen to that brother.
C# is like C++ only managed haven't worked with it for like 2 years but it had more features then java but less built in data structures if i remembered it right could have changed in those 2 years.

Tab 4 spaces or 8 spaces?

Holy shit. TWO spaces. And I use spaces instead of tabs because, as I saw it mentioned earlier, it provides far greater flexibility.

As for curly braces?

Code:
void thisIsHowYouDoIt (int oh, int yeah) {
  print "there is no other way"
}

edit: I've never really done much C# (only a tutorial or two on WP development when it first came out), you need to capitalize method names, really? Ugh
 
Holy shit. TWO spaces. And I use spaces instead of tabs because, as I saw it mentioned earlier, it provides far greater flexibility.

As for curly braces?

Code:
void thisIsHowYouDoIt (int oh, int yeah) {
  print "there is no other way"
}

edit: I've never really done much C# (only a tutorial or two on WP development when it first came out), you need to capitalize method names, really? Ugh

Have to use all that glorious horizontal screen space 16:9 ftw.
 

ferr

Member
New line. My problem with same line braces is the lack of symmetry.

Code:
function ThisShitUgly(){
     // Ugly scrunched shit
} // What is this thing even doing here?

function GloriousSymmetry()
{
     {
          // Love it
     }
}

Co-worker of mine said he does the brace of the same line as the function name because the end brace lines up 'with the code block' ie with the function keyword in this case. It's an irrational explanation, something always lines up with something.
 

Magni

Member
Code:
void thisIsHowYouDoIt( int oh, int yeah ) 
{
    print "there is no other way"
}

4 spaces all the way.
Also: http://programmers.stackexchange.com/a/2786

Yeah, but that only applies if you're putting your function or method arguments on different lines. In that case, I would also put the brace on a new line. But I almost never (can't remember the last time I ever did that) split my arguments by line.

You don't have to. But it is the convention.

Yeah that's what I meant.
 

msv

Member
Meh, it's something the IDE should be handling IMO. Arguing about how to write it best isn't going to do anyone any good. Just because you write a lot of code, doesn't make you an expert in readability. IDE developers need to improve readability of code instead of keeping the status quo as a mere glorified text editor. There's no reason there can't be non-textual indications, enhancing readibility, instead of mucking about with braces, white lines, colored text.
 

Lathentar

Looking for Pants
Meh, it's something the IDE should be handling IMO. Arguing about how to write it best isn't going to do anyone any good. Just because you write a lot of code, doesn't make you an expert in readability. IDE developers need to improve readability of code instead of keeping the status quo as a mere glorified text editor. There's no reason there can't be non-textual indications, enhancing readibility, instead of mucking about with braces, white lines, colored text.

Yeah, I'd rather the IDE just modify the display of the code to match the user's preferences.
 

mike23

Member
Yeah, I'd rather the IDE just modify the display of the code to match the user's preferences.

This. I'd love if Visual Studio saved all code files in a formatting invariant way. It'd make it a lot nicer for multiple developers to use different auto-formatting settings, like tabs vs spaces, without screwing up source control or annoying everyone else.
 

usea

Member
The benefit of tabs is each user can have their tab with whatever they want. It doesn't impose indention width, it sets it free.

Spaces are for lining things up, tabs are for indenting. That's what they're for, and they're better at it than spaces.

I could go either way on braces, but tabs? Spaces provide the most flexibility.

Code:
// no doing this with tabs
bool X::operator==(const X& rhs) const {
	return y == rhs.y
	    && z == rhs.z;
}
edited your code to have tabs instead of spaces. If this was an ide, the width would be the same (because you set your tab viewing width to be whatever you want). Tabs to indent, spaces to align.
 
C#/C++
Code:
int SuperFunctionEX(string param1, int param2)
{
    int lol = 3;
    return lol * 4;
}
JS
Code:
var Modulator = (function() {
    var haha = 4;
    return {
        Foo: function(win) {
            return haha * win;
        }
    };
}());
Also, gogo spaces :)
 
Can anyone recommend a good data structures book for java? I want to get a head start next month when I take it. Almost done reading headfirst java(been taking it slowly) and it seems they don't get in depth about it.
 

Godslay

Banned
Can anyone recommend a good data structures book for java? I want to get a head start next month when I take it. Almost done reading headfirst java(been taking it slowly) and it seems they don't get in depth about it.

The best data structures and algorithms book is the CLRS. It's not language specific though, so if you are looking for specific language examples it might not be your best choice though.

You can find it here, a bit expensive, but it is the best and will remain with a person for a long time:

http://www.amazon.com/Introduction-Algorithms-Thomas-H-Cormen/dp/0262033844/ref=sr_1_1?ie=UTF8&qid=1366566548&sr=8-1&keywords=clrs


I found this via StackOverflow, browsed through, it looks good for a java implementation free as well, seems to cover the good stuff:

http://dept.cs.williams.edu/~bailey/JavaStructures/Book_files/JavaStructures.pdf

Source code for the book:

http://dept.cs.williams.edu/JavaStructures//Software.html

I'm sure there are more if you look around.
 
Can anyone recommend a good data structures book for java? I want to get a head start next month when I take it. Almost done reading headfirst java(been taking it slowly) and it seems they don't get in depth about it.

Dunno how good it really is, but a course I read recently used this one.

----

And also, regarding the VHDL thing I mentioned on the last page I've managed to get tiles and palettes working as well, so I can now use 16 different 16x16 tiles in a whopping 256 colors (well, I have to pick 16 that I can use...) but I still have this weird problem. As you can see there's a black streak going through the leftmost tiles, and I have no idea what causes it. I use three different tiles here, just for testing purposes. I'm gonna ask my professor about it, since it's seriously driving me nuts.

RB6SLnj.jpg
 

iapetus

Scary Euro Man
Co-worker of mine said he does the brace of the same line as the function name because the end brace lines up 'with the code block' ie with the function keyword in this case. It's an irrational explanation, something always lines up with something.

At the end of the day, all explanations of these things are irrational. It all comes down to preference, mostly based on which model you learnt to code with.

That and a crippling genetic defect causing people to suffer from the terrible crime of putting opening braces on a new line.
 

pompidu

Member
Not sure what to do here, can't seem to find an answer online. I need to take a text file and generate a list of contacts but im not sure how to recieve a text argument as a parameter.
Here's part of the tester.
Code:
ContactList cL = new ContactList("src\\contacts.txt");

I have no idea what to put in the parameters for the constructor of the ContactList class.
Code:
public ContactList()
	{
		
	}
Anyone shed some light on this please??
 

arit

Member
Can anyone recommend a good data structures book for java? I want to get a head start next month when I take it. Almost done reading headfirst java(been taking it slowly) and it seems they don't get in depth about it.

Buy Introduction to Algorithms by CLRS. Languages change, but the fundamental basics are rather longevous. So buy once, read forever.
Sure, language-specific books might make it a bit easier if your goal is to just c&p, but due to the univerality of said book, you might learn more from it as you have to think which language tools you'll use in the end.

As for formating, spaces only. One thing I learned during working on different systems, with different editors is that they can destroy all readability you had, unless you take the time to configure them before using them.
 

hateradio

The Most Dangerous Yes Man
Yeah, I'd rather the IDE just modify the display of the code to match the user's preferences.
If I use Eclipse, which I don't like, I do just let it format the code for me when I'm done with writing things. (CTRL+SHIFT+F, I believe.)

Otherwise, I do want I want. 8)
 
I used this book in my data structures class, though it was in C. My professor admitted that there were better resources to learn from. I found the book to be awful, but that is only my two cents.

He asked for a java one and that is the only one i know. And has a high amazon rating its not some casual book most people will read for fun and troll review.
But as far as im told this is the defacto bible on data structures and algorithms.

http://www.amazon.com/Introduction-Algorithms-Thomas-H-Cormen/dp/0262033844

Haven't read it maybe will in the summer but i have like 20 book right now i all bought for cheap that i still need to read, but have no time for and technical books read extremely slow because im still a beginner and need to takes notes :(

I love browsing ebay and find some pearls for $15 especially in feb and before the summer stop when people decide its to hard and stop or are done and sell off their school books why i dont know but sometimes i strike gold and find a copy as good as new for 1/4 of the price.
 

Feep

Banned
Soooo.

After learning that the System.Speech .NET library is completely and in every way incompatible with Unity, I need a way to make that shit work. And the way to make that shit work is to write a plugin that works with the native SAPI 5.4 Win32 libraries. I think.

And I don't know nearly enough C++ to make that happen.

What would something like this cost me? I have absolutely no idea, but I have to figure it out. And if any of you guys are up for the job, let me know. I got bucks.
 

Bollocks

Member
New line. My problem with same line braces is the lack of symmetry.

Code:
function ThisShitUgly(){
     // Ugly scrunched shit
} // What is this thing even doing here?

function GloriousSymmetry()
{
     {
          // Love it
     }
}

I used to think like this but it really depends on the context.
When I'm programming in C/C# I put the braces on newline, when I have to do something in JavaScript/ActionScript I'll use the latter
 

Slavik81

Member
Not near my computer now, but I know it has to do with the initialization of the vector vs the initialization of the array.
I presume you're referring to just using push_back repeatedly on the vector? You know you can just reserve the space from the start, exactly as you would with a dynamically allocated array? vector provides convenient ways of appending which do have an additional cost, but you don't pay for them if you don't use them.

Alas, I was struck by lazyness this weekend and didn't make put together an example like I meant to...

In an optimized build, the only notable performance difference between a dynamically allocated array and a vector should be that a vector also includes an extra variable to track its size. And you won't notice a difference that insignificant in a test like the one you described.

Soooo.

After learning that the System.Speech .NET library is completely and in every way incompatible with Unity, I need a way to make that shit work. And the way to make that shit work is to write a plugin that works with the native SAPI 5.4 Win32 libraries. I think.

And I don't know nearly enough C++ to make that happen.

What would something like this cost me? I have absolutely no idea, but I have to figure it out. And if any of you guys are up for the job, let me know. I got bucks.

This makes me wish I knew the slightest thing about Unity and/or Windows Speech.
 
I'd love to help you out with this Feep (especially since I assume this is for There Came an Echo?) but I don't think I have the time. Do you just want to call existing functions in the windows SAPI or do you need a more robust interface?
 
After learning that the System.Speech .NET library is completely and in every way incompatible with Unity, I need a way to make that shit work. And the way to make that shit work is to write a plugin that works with the native SAPI 5.4 Win32 libraries. I think.

Could you spawn a separate program for the speech components and then write some code to make Unity and that program communicate? Might be a way around it if you are trying to avoid C++ and are already comfortable with the library.

Depending on your platform, this might also help you swap out something that isn't windows specific. From memory mono doesn't support it properly yet as you probably know.
 

The best data structures and algorithms book is the CLRS. It's not language specific though, so if you are looking for specific language examples it might not be your best choice though.

You can find it here, a bit expensive, but it is the best and will remain with a person for a long time:

http://www.amazon.com/Introduction-Algorithms-Thomas-H-Cormen/dp/0262033844/ref=sr_1_1?ie=UTF8&qid=1366566548&sr=8-1&keywords=clrs


I found this via StackOverflow, browsed through, it looks good for a java implementation free as well, seems to cover the good stuff:

http://dept.cs.williams.edu/~bailey/JavaStructures/Book_files/JavaStructures.pdf

Source code for the book:

http://dept.cs.williams.edu/JavaStructures//Software.html

I'm sure there are more if you look around.

Thanks guys for the responses. Hopefully my local bookstore has each of them and I can give each a try. Then choose which clicks for me. That free one is looking good about now though since I'm a bit tight on cash lol.

I remember someone recommending me this out of print book that was supposedly really good. I can't remember the name now..
 

Red UFO

Member
Hi guys, I have a std::list of numbers, and I'd like to remove any numbers that are repeated twice. I can assume all lists passed into the function will be in ascending order and as such all repeats will be next to each other (e.g. <1,2,3,3,4,5> etc.).

We're also to find the product of any removed numbers (for example, a list of <1,2,2,3,3,4,5> would return 6 (2*3)).

Here is my code:

Code:
#include <list>
#include <algorithm>
#include "p6.h"
unsigned p6(std::list<unsigned> & factors, const unsigned repeats){
	int repeatedValue;
	int product=1;
	std::list<unsigned>::iterator it;	
	it = std::adjacent_find (factors.begin(), factors.end());
	if (it!=factors.end()){
		repeatedValue=*it;
		it = factors.erase(it);
		it = factors.erase(it);
	}
	product = product*repeatedValue;	
	return product;
}

My problem is getting the program to perform the adjacent find more than once, any attempt to put it in a while loop gives me errors such as "list iterators incompatible" or "list iterator is not deferenceable."

Can anybody explain to me what these errors mean and/or why I'm getting them? I feel like there's something about iterators I'm not understanding.

d[-_-]b;54848976 said:
It's been a mediocre experience all together, but any reason why you say this?
I don't like coding in Java to start off with (I feel like I'm asking if I can do stuff, instead of just doing stuff like in C++), putting all the Android stuff on top of that just made things worse. I also didn't like using the SDK, it likes to give weird errors for no reason, I found. When it works, it's great, but I just find myself fighting against more often than not.
 

Zeppelin

Member
Hi guys, I have a std::list of numbers, and I'd like to remove any numbers that are repeated twice. I can assume all lists passed into the function will be in ascending order and as such all repeats will be next to each other (e.g. <1,2,3,3,4,5> etc.).

We're also to find the product of any removed numbers (for example, a list of <1,2,2,3,3,4,5> would return 6 (2*3)).

Here is my code:

Code:
#include <list>
#include <algorithm>
#include "p6.h"
unsigned p6(std::list<unsigned> & factors, const unsigned repeats){
	int repeatedValue;
	int product=1;
	std::list<unsigned>::iterator it;	
	it = std::adjacent_find (factors.begin(), factors.end());
	if (it!=factors.end()){
		repeatedValue=*it;
		it = factors.erase(it);
		it = factors.erase(it);
	}
	product = product*repeatedValue;	
	return product;
}

My problem is getting the program to perform the adjacent find more than once, any attempt to put it in a while loop gives me errors such as "list iterators incompatible" or "list iterator is not deferenceable."

Can anybody explain to me what these errors mean and/or why I'm getting them? I feel like there's something about iterators I'm not understanding.


I don't like coding in Java to start off with (I feel like I'm asking if I can do stuff, instead of just doing stuff like in C++), putting all the Android stuff on top of that just made things worse. I also didn't like using the SDK, it likes to give weird errors for no reason, I found. When it works, it's great, but I just find myself fighting against more often than not.

For each element in the list, check if the next one is equal to it. If so, multiply it onto a variable initialized to 1 (this is where your product ends up) and remove it from the list. Then check the next element's value again (this step is not necessary if a value can only be repeated once), do the same if it's equal again, otherwise move to the next item in the list.

Edit: If the product then is 1 when you've gone through the list it means no repeated values were found and you should set the product variable to 0.

Hmm, that's the first time I come across this style. I think I'm gonna try it out whenever I work on a new Java/C++ project.

It's neat. But remember, the kernel is written in C, so all of it doesn't necessarily makes sense in other languages. You can read some of the rationale behind it here: http://yarchive.net/comp/linux/coding_style.html
 

Red UFO

Member
You've described std::unique.

For each element in the list, check if the next one is equal to it. If so, multiply it onto a variable initialized to 1 (this is where your product ends up) and remove it from the list. Then check the next element's value again (this step is not necessary if a value can only be repeated once), do the same if it's equal again, otherwise move to the next item in the list.

Edit: If the product then is 1 when you've gone through the list it means no repeated values were found and you should set the product variable to 0.
Thanks guys!
 

6.8

Member
I'm writing code on paper to practice whiteboard coding for job interviews. I'd rather be waterboarded than do this shit. But you gotta do what you gotta do.
 

Jokab

Member
I'm writing code on paper to practice whiteboard coding for job interviews. I'd rather be waterboarded than do this shit. But you gotta do what you gotta do.

All programming exams at my university are on paper. I don't know if that's what everyone does, but it sure sucks in any case.
 

Zeppelin

Member
All programming exams at my university are on paper. I don't know if that's what everyone does, but it sure sucks in any case.

I've had both. The language specific ones were done on computers, the more theoretical stuff on paper. Paper is not bad, it forces you to actually think before you start writing. Well, except for the design patterns exam, that shit got painful.
 

Jokab

Member
I've had both. The language specific ones were done on computers, the more theoretical stuff on paper. Paper is not bad, it forces you to actually think before you start writing. Well, except for the design patterns exam, that shit got painful.

Tell me about it. Our first exam also had Java swing, that wasn't fun at all to write on paper.
 

Feep

Banned
Could you spawn a separate program for the speech components and then write some code to make Unity and that program communicate? Might be a way around it if you are trying to avoid C++ and are already comfortable with the library.

Depending on your platform, this might also help you swap out something that isn't windows specific. From memory mono doesn't support it properly yet as you probably know.
This might still be beyond my skill level, but is that viable? Can I compile some sort of .exe that opens both a Unity game and a non-windowed .NET application beside it, with one piping in data to another?
 

Aurongel

Member
All programming exams at my university are on paper. I don't know if that's what everyone does, but it sure sucks in any case.

Yup, all of my CS exams are completely on paper also. It takes FOREVER and makes it easy to forget your place or the values of certain things. Or maybe I'm just not that good at it.
 
Top Bottom