• 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

Two questions:
1. What's a good debugger for C?
2. How do I write\suggestions to write cleaner code? lol I never had to work with anyone before(well, I did but I did all the work) so I never really had to worry about that. However, my partner hated looking at my code. When I looked at his, his was easier to debug than it was to debug mine. So I realize, I spent more time trying to figure out what my code does than debugging it. So when I looked at my partner's code, I looked at what his code does and fixed it rather fast since it was easier to follow.
 
Two questions:
1. What's a good debugger for C?
2. How do I writesuggestions to write cleaner code? lol I never had to work with anyone before(well, I did but I did all the work) so I never really had to worry about that. However, my partner hated looking at my code. When I looked at his, his was easier to debug than it was to debug mine. So I realize, I spent more time trying to figure out what my code does than debugging it. So when I looked at my partner's code, I looked at what his code does and fixed it rather fast since it was easier to follow.


1: what platform, compiler and ide ate you using? generally, I stick to the ones that are already available.


2: I'm curious to see what your code looks like. Code conventions are highly subjective, so its hard to give proper recommendations.


One thing that's very important to remember is that code is written once but is read many times; it's better to be more verbose rather than writing code that is quick to write. Take time to name your functions, variables and types appropriately. Don't write functions that are too long as they are harder to read: by moving parts of a long function to their own functions, it will not only make the function shorter, you'll also get descriptions of those parts, as long as you named the functions appropriately.
 

Slavik81

Member
Two questions:
How do I write\suggestions to write cleaner code? lol I never had to work with anyone before(well, I did but I did all the work) so I never really had to worry about that. However, my partner hated looking at my code. When I looked at his, his was easier to debug than it was to debug mine. So I realize, I spent more time trying to figure out what my code does than debugging it. So when I looked at my partner's code, I looked at what his code does and fixed it rather fast since it was easier to follow.
If you can find a copy of Code Complete, I think it's a pretty decent guide to basic code cleanliness.
 
1: what platform, compiler and ide ate you using? generally, I stick to the ones that are already available.


2: I'm curious to see what your code looks like. Code conventions are highly subjective, so its hard to give proper recommendations.


One thing that's very important to remember is that code is written once but is read many times; it's better to be more verbose rather than writing code that is quick to write. Take time to name your functions, variables and types appropriately. Don't write functions that are too long as they are harder to read: by moving parts of a long function to their own functions, it will not only make the function shorter, you'll also get descriptions of those parts, as long as you named the functions appropriately.
1. I was using eclipse since I coded in java before but now my classes are all in C. I wasn't really like eclipse for C since the features that were for java weren't there and I found it easier to use notepad++ since they highlighted where the {} were. But I just installed netbeans so I'll try that.

2. That's what I usually do but I'm still new to C so I wasn't sure what I could pass in an argument or not. Like before, all I wanted was to pass a struct's arrays or its contents at a certain point, let another function do it but I couldn't do that. Rather, I didn't know how. I'm not done reading the book I'm using to learn C yet so hopefully it explains it.

If you can find a copy of Code Complete, I think it's a pretty decent guide to basic code cleanliness.
Thanks, I'll look into this.

Just curious, what IDE does everyone use here?
Do you always need a make file to debug? Netbeans seems like it needs it just to run/debug it.
 

nan0

Member
Code Complete is a good book, but might be a bit overwhelming for novices with no experience in larger (as in: not just small homework programs) projects.

Just curious, what IDE does everyone use here?
Do you always need a make file to debug? Netbeans seems like it needs it just to run/debug it.

I use IntelliJ IDEA for Java/Android, Visual Studio for C/C++/C#. Debugging is integrated in all major IDEs. Just set a breakpoint and start debugging (some IDEs explicitly distiguish between running and debugging).
 

Water

Member
I'm wondering, why would you use a text editor like Sublime Text 3 over using an IDE with a compiler?
Because the best text editors can be much better for editing text than the text editors that come with IDEs. To get some benefit out of them, you need to learn to use them though. If you put no time into learning how to use the editor, you might as well just use the crappier editor in the IDE.
 
Just curious, what IDE does everyone use here?
Do you always need a make file to debug? Netbeans seems like it needs it just to run/debug it.

Linux terminal with vi and gdb. Nope, I just set the -g flag for gdb upon compiling!
Unless it's a larger project then yes, I use a makefile.
 
I'm wondering, why would you use a text editor like Sublime Text 3 over using an IDE with a compiler?

I've not really looked into Sublime before, but Eclipse and VS both support vim (as should any IDE worth its salt, + emacs).

It's just unfortunate that vim support in VS is locked behind a paywall.
 
Just curious, what IDE does everyone use here?
Do you always need a make file to debug? Netbeans seems like it needs it just to run/debug it.

The bulk of what I do is Linux/*nix based and I use either Geany or vim, depending on platform. For this kind of setup you want makefiles as soon as the project is bigger than one file / has to have libraries included, but not necessary to debug no.
 

tokkun

Member
vim with the YouCompleteMe + Syntastic plugins

I prefer a more lightweight editing environment compared to an IDE like Eclipse. Starts up faster, low memory footprint, and runs well over SSH. Provides features I need the most (auto-complete, indexing, incremental compile) without a bunch of stuff I am never going to use.

Only real complaints are that YCM can be a bit of a hassle to install on distros that don't ship with a new enough version of vim with python support, and not all languages are well-supported.
 

phoenixyz

Member
Because the best text editors can be much better for editing text than the text editors that come with IDEs. To get some benefit out of them, you need to learn to use them though. If you put no time into learning how to use the editor, you might as well just use the crappier editor in the IDE.
This. Sublime Text is (imho of course) superior to the editors in, for example, Eclipse or Visual Studio. And as ST is very extensible you can get quite some IDE features you need as plugins.
 
What is the general consensus for number of functions within a file? I'm getting larger and larger programs at university and the growing amount of functions and files has me wondering what is the best way to structure them. Is it mainly all the functions dealing with a certain module of the program are in one file or is there a better way to do it?
 
Just started a CS masters and I've been tasked with creating an online multiplayer game. Where the heck should I start with online multiplayer in C++, in terms of framework?
 

jokkir

Member
Quick question about Perl.

I'm getting a bit mixed up between PHP and Perl. In Perl, can you put standard html tags and then at the top of the page Perl code?

Like for example:
Code:
!/usr/bin/perl

#--Perl Code--
print "Content-Type: text/plain\n\n";

use CGI qw( :standard );

##Perl stuff here#

#--End of Perl code--

#HTML stuff
<!DOCTYPE html>
<html>
	<head>
		<title>Testing</title>
	</head>
	<body>
		This is HTML code
	</body>
</html>

I'm trying to make a form out of it.

I know you can do something like that with PHP but can you do it with Perl? If now, what is the approach?
 
Quick question about Perl.

I'm getting a bit mixed up between PHP and Perl. In Perl, can you put standard html tags and then at the top of the page Perl code?

Like for example:


I'm trying to make a form out of it.

I know you can do something like that with PHP but can you do it with Perl? If now, what is the approach?

Disclaimer: It's been ages since I did Perl, so yeah, I might be wrong...

No, Perl cannot do this. Something equivalent would be a heredoc

Code:
my $content = <<EOD;
... entity ...
EOD

print $content;

That would be good for very simple documents (no loops, no conditions), as the only thing it can do, outside of a multi-line strings, is variable interpolation. For anything more complex, you should use some kind of templating engine.
 

Water

Member
Just started a CS masters and I've been tasked with creating an online multiplayer game. Where the heck should I start with online multiplayer in C++, in terms of framework?
What are the other parameters for the assignment? What do you actually want to make? If it's just "create online multiplayer game", a text-based heads up Texas Hold'em game is a valid submission, and any tiny library that can do basic sockets would be sufficient.

SFML would not be a bad choice; it's got graphics/sound/etc. as well if you need/want to do more.
http://sfml-dev.org/documentation/2.0/classsf_1_1Socket.php
 
What are the other parameters for the assignment? What do you actually want to make? If it's just "create online multiplayer game", a text-based heads up Texas Hold'em game is a valid submission, and any tiny library that can do basic sockets would be sufficient.

SFML would not be a bad choice; it's got graphics/sound/etc. as well if you need/want to do more.
http://sfml-dev.org/documentation/2.0/classsf_1_1Socket.php

One thing to note is that SFML mostly supports 2D, so if you want to go 3D, you have to fall back on regular OpenGL (which is also supported in SFML, however it lacks 4D vector and matrix classes).
 
What's up with glDisplayLists...? The image shows a model I created and textured on Blender. I'm rendering 15 of him using my model loader.

Previously I did not use display lists, I just had raw immediate mode. The FPS at that time would probably be 11, or something disgusting. Now I'm using display lists and I'm stuck at 60 fps! Can someone explain the magic of display lists?!

PGYufEP.png
 

Water

Member
What's up with glDisplayLists...? The image shows a model I created and textured on Blender. I'm rendering 15 of him using my model loader.

Previously I did not use display lists, I just had raw immediate mode. The FPS at that time would probably be 11, or something disgusting. Now I'm using display lists and I'm stuck at 60 fps! Can someone explain the magic of display lists?!
You are supposed to get more performance when using display lists, so that doesn't sound so weird. Do you mean your FPS doesn't go any higher, even if you render fewer dudes? If so, that would sound like you have Vsync on, in which case the GPU won't render more frames than the refresh rate of the screen.

But seriously, old GL is ugly. Modern GL only hurts at the very beginning when you have to get your data into buffers; after that it's smooth sailing and shaders.
 
You are supposed to get more performance when using display lists, so that doesn't sound so weird. Do you mean your FPS doesn't go any higher, even if you render fewer dudes? If so, that would sound like you have Vsync on, in which case the GPU won't render more frames than the refresh rate of the screen.

But seriously, old GL is ugly. Modern GL only hurts at the very beginning when you have to get your data into buffers; after that it's smooth sailing and shaders.

I have a timer function that locks it at 62.5 fps.

While googling a lot of things I found display lists, but before that I saw a lot of GLSL stuff. I don't quite feel like learning that yet.
 
You are supposed to get more performance when using display lists, so that doesn't sound so weird. Do you mean your FPS doesn't go any higher, even if you render fewer dudes? If so, that would sound like you have Vsync on, in which case the GPU won't render more frames than the refresh rate of the screen.

But seriously, old GL is ugly. Modern GL only hurts at the very beginning when you have to get your data into buffers; after that it's smooth sailing and shaders.
Is there a good tutorial/reference for working with Modern GL? I want to get back into it, but every time I wuss out after a few PTSD flashbacks of the old-style openGL stuff I did years ago in college.
 

Water

Member
Is there a good tutorial/reference for working with Modern GL? I want to get back into it, but every time I wuss out after a few PTSD flashbacks of the old-style openGL stuff I did years ago in college.
Here you go.

The old GL is PTSD-inducing because the API is horrible, but especially because it's an elaborate state machine you can't see, only change a bit at a time with function calls. You kind of have to mentally keep track of that state all the time while reading the code. In modern style you do a little bit more stuff manually up front (like set up your own perspective/camera/model matrices - no one does that for you), but you learn those basics better, and the whole apparatus is both easier and far more flexible. The API is still ugly, but at least you don't have to use many functions - for the most part, you just use a couple of generic GL calls to push data to the shaders, where your own shader code uses it - and there's much less state to deal with. GLSL shaders themselves are very easy to code. Writing a bunch of calculations is easier in GLSL than with even the best C++ math library I've seen.
 

NotBacon

Member
Ok, I'll be that guy, what does a debugger do?

I've written programs thousands of lines in length and in various languages, but I've never used a debugger. What does it do and how does it work? I usually just look at any compile or runtime errors and track them down.
 
Ok, I'll be that guy, what does a debugger do?

I've written programs thousands of lines in length and in various languages, but I've never used a debugger. What does it do and how does it work? I usually just look at any compile or runtime errors and track them down.

A debugger let you inspect a running program. You can tell it to stop the execution at some place in your code, see the state (variables values) at the current point, continue the execution one expression at a time, see the call stack (functions that lead to the current function call).
 

Water

Member
Ok, I'll be that guy, what does a debugger do?

I've written programs thousands of lines in length and in various languages, but I've never used a debugger. What does it do and how does it work? I usually just look at any compile or runtime errors and track them down.
It depends a lot on the language and the type of code you are writing how useful debuggers are; typically they are really beneficial when working with languages like C, and not necessarily used at all with languages like Haskell. It's always best if you can get the compiler to catch problems before they start, but once stuff happens at runtime, a debugger can be worth its weight in gold. For instance, your basic runtime crash can take time to track down without a debugger, but with a debugger, you can immediately see the whole call stack that led to the crash. Having a debugger is even more important when things go wrong and you don't really know how it happened; stepping through the code gives you insight.
 
Here you go.

The old GL is PTSD-inducing because the API is horrible, but especially because it's an elaborate state machine you can't see, only change a bit at a time with function calls. You kind of have to mentally keep track of that state all the time while reading the code. In modern style you do a little bit more stuff manually up front (like set up your own perspective/camera/model matrices - no one does that for you), but you learn those basics better, and the whole apparatus is both easier and far more flexible. The API is still ugly, but at least you don't have to use many functions - for the most part, you just use a couple of generic GL calls to push data to the shaders, where your own shader code uses it - and there's much less state to deal with. GLSL shaders themselves are very easy to code. Writing a bunch of calculations is easier in GLSL than with even the best C++ math library I've seen.
Sounds reasonable. Thanks for the link, looks like it'll be handy.
 
Once I start entering my programming classes for my degree program, I imagine I'll be frequenting here more. Scared to death of programming. Could barely wrap my head around WarioWare D.I.Y let alone an entire language.
 

Godslay

Banned
Once I start entering my programming classes for my degree program, I imagine I'll be frequenting here more. Scared to death of programming. Could barely wrap my head around WarioWare D.I.Y let alone an entire language.

Piece by piece. It's just like anything else. Learn something, use it, break it, fix it. Rinse and repeat. Nothing to be scared of.
 

Water

Member
Once I start entering my programming classes for my degree program, I imagine I'll be frequenting here more. Scared to death of programming. Could barely wrap my head around WarioWare D.I.Y let alone an entire language.
Have you tried? If your classes aren't starting right away, you can get a head start. As long as you go with a friendly language/environment/materials, it's easy to dip your toes in, and that's something Gaf can set you up with. I think you'd find it's not that scary, and that way you won't have time pressure.
 

Relix

he's Virgin Tight™
If you were starting from scratch (assume you already know HTML, CSS, JavaScript), which web programming language would you learn?

PHP. Will get you into all the basics and more.


These days I am working with C# and ASP.NET which I find fantastic, will be moving to MVC type development soon.
 
Have you tried? If your classes aren't starting right away, you can get a head start. As long as you go with a friendly language/environment/materials, it's easy to dip your toes in, and that's something Gaf can set you up with. I think you'd find it's not that scary, and that way you won't have time pressure.

Not yet, I'm saving those classes when I don't have as many demanding classes because I know it will probably take me some extra time to learn.
 

kingslunk

Member
Once I start entering my programming classes for my degree program, I imagine I'll be frequenting here more. Scared to death of programming. Could barely wrap my head around WarioWare D.I.Y let alone an entire language.

Yeah the way programming is taught at most universities really start and progress at a pretty good rate. When I was doing my undergrad in Comp Sci when I first started I was pretty nervous but it ended up being by far my favorite and easiest class (because I enjoyed it so much).

Not yet, I'm saving those classes when I don't have as many demanding classes because I know it will probably take me some extra time to learn.

Do you know what language you'll be starting with?
 

Godslay

Banned
PHP. Will get you into all the basics and more.


These days I am working with C# and ASP.NET which I find fantastic, will be moving to MVC type development soon.

I'd say skip PHP and jump right into C#, ASP.NET, either MVC or Webforms. I know some will laugh at webforms, but like Hanselman says webform developers are the dark matter of the web. Plus you get the benefit of working with VS, and Entity Framework. Also, emmet is awesome if you have web developer tools installed.
 

Milchjon

Member
Does anyone have a link to a good overview over different IDEs?

I have access to Visual Studio via university, any downsides to it?
 
Does anyone have a link to a good overview over different IDEs?

I have access to Visual Studio via university, any downsides to it?

For what languages and what platform? If you are only coding for Windows, Visual Studio is god tier.

For others just google and go to wikipedia. You can get a pretty good sense of what is out there.
 

Water

Member
I have access to Visual Studio via university, any downsides to it?
The C++ compiler and standard library shipping with the current version, VS2012, are lacking a lot of functionality from the C++11 standard. This is a real problem and forces me to write some code that is just ugly. VS2013, now in its release candidate version, is a lot better. Still not perfect though.

The biggest reason to use Visual Studio is the debugger. For a compiler and for a text editor, there are a lot better options.
 

delirium

Member
I just took a job where the main language is Java. I'm going to miss C# and its features. I understand Java 8 has support for lambdas but no first class functions.
 
Top Bottom