• 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

Yeah I finally understand that. Wasn't thinking about it in the right way.

Ok so I got rid of the sides member variable in FunnyDie.

However, there is an error with trying to use setSides() with a FunnyDie. Because sides is a private member variable of the Die class. Even though setSides() is a public function of the die class.

Changing sides to a protected member variable fixed that I think.

Did you take the setSides function back out of the FunnyDie class? (Assuming it doesn't need to override the default behavior, you should.)
 
to clarify, yes I did take setSides() out of funnyDie. It only exists in Die as a public function.

I still get the error though. Actually the error appears in visual studio, but it seems to compile and run just fine.
 

Koren

Member
However, there is an error with trying to use setSides() with a FunnyDie. Because sides is a private member variable of the Die class. Even though setSides() is a public function of the die class.
That shouldn't be the case...

using a protected nbsides is only useful if you want methods from funnydie to be able to access it (and still preventing the direct access to the data from outside the class).

This works, for example:
Code:
#include <stdio.h>

class die {
	private :
		int nbsides;
	
	public :
		void setSides(int n) { nbsides = n; }
		int getSides() { return nbsides; }
		die() {}
		~die() {}
};

class funnydie : public die {
	public :
		funnydie() {}
		~funnydie() {}
};

int main(int argc, char* argv[]) {
	funnydie d;
	
	d.setSides(6);
	
	printf("%d\n", d.getSides());
}
 
to clarify, yes I did take setSides() out of funnyDie. It only exists in Die as a public function.

I still get the error though. Actually the error appears in visual studio, but it seems to compile and run just fine.

Visual Studio probably is confused by an artifact from a previous build. You might try doing a full rebuild to get the erroneous build error to go away.
 

Onemic

Member
Is it necessary to learn Digital Design if I'm trying to get into graphics programming? I have the book Digital Design and Computer Architecture by Harris and Harris and nearly the first half of the book is dedicated to digital/logic design and VHDL/SystemVerilog. Is it necessary or beneficial to learn towards becoming a graphics programmer or can I skip it and jump straight into the chapters concerning computer architecture?

For context, I've already read through and completed the exercises of the first chapter and have read through about half of the second chapter. If I jumped to the parts concerning computer architecture I'd skip about 3 chapters total, including the half finished chapter 2.
 
Good luck on your interview!

Thank you!

It ended up not being so much an interview as a establishing contact and letting me know that they'll be hiring soon, but not right now. I ended up having to take an aptitude test conducted by another company online (CEB/SHL). It was pretty tough and honestly I don't feel so hot coming off of it, but I imagine most candidates don't and I don't know where they set the bar at. It had a lot of truth tables and conditional logic, and some image flipping problems (unsure where that fits into traditional programming). I'm a programmer that enjoys the safety net of being able to test my logic on the fly with a compiler, so given 3 minutes per question was pretty stressful for me.

Fortunately I prefer this to being hired and then let go later because I'm not suited for the job.
 
Is it necessary to learn Digital Design if I'm trying to get into graphics programming? I have the book Digital Design and Computer Architecture by Harris and Harris and nearly the first half of the book is dedicated to digital/logic design and VHDL/SystemVerilog. Is it necessary or beneficial to learn towards becoming a graphics programmer or can I skip it and jump straight into the chapters concerning computer architecture?

For context, I've already read through and completed the exercises of the first chapter and have read through about half of the second chapter. If I jumped to the parts concerning computer architecture I'd skip about 3 chapters total, including the half finished chapter 2.

skip it
 

ohlawd

Member
say I want to make n files in a folder using command prompt, how do I go about doing this? I have to use a for loop and set to do increments, right?

like if I want 20 text files, it'd make them 1, 2, 3... 20.txt. if I only want three, then it'd make 1.txt, 2.txt, 3.txt

for %b in... all I got lol
 

Koren

Member
say I want to make n files in a folder using command prompt, how do I go about doing this? I have to use a for loop and set to do increments, right?

like if I want 20 text files, it'd make them 1, 2, 3... 20.txt. if I only want three, then it'd make 1.txt, 2.txt, 3.txt

for %b in... all I got lol
You want empty files?

In Bash?

Code:
for i in `seq 1 3`; do touch $i.txt; done

?
 

Koren

Member
can't do Bash tho, whatever the heck that is :p
One of the most common Unix shells...

So, I guess it's vanilla Windows? From the command line?

I'll try again... (but I'm rustier in Windows command line, I use Bash even on Windows, although I know people here will say I should use native power shells ^_^ )

Code:
for /L %i in (1, 1, 5) do type nul > %i.txt

Edit: just to clarify: it'll create 5 files from 1.txt to 5.txt, all empty. You can put this in a batch file if you prefer (and you can even run it from explorer). It's possible to open a dialog box to ask for the value if you want.
 
Windows command line is ok, but its for loops made me give it up. I just can't understand them for some reason.

On a separate note, does anybody know of a good way to learn WPF? I've got a decent grasp on it, but learning anything new makes me feel like I've not learned enough of the basics.
 
Windows command line is ok, but its for loops made me give it up. I just can't understand them for some reason.

On a separate note, does anybody know of a good way to learn WPF? I've got a decent grasp on it, but learning anything new makes me feel like I've not learned enough of the basics.

WPF man. That fucking thing. I don't know what to say about it. It makes impossible things easy, and easy things impossible.
 

Koren

Member
If you are on windows use Powershell, please.
It's really nice, and I'd recommand it to anyone using mostly or only Windows, but I don't use Windows enough myself to warrant using a different set of tools than when I'm on my Linux machines...

I was actually surprised that it's available in Seven but hidden while Command is still on the front.

If you refer to the answer I give, I admit I don't remember well how you properly write a loop in powershell (I think I remember there's a C-like syntax with strange replacements for comparisons, and a 1..N | { action } structure that seemed quite interesting)
 
That feeling when you made a data structure too big and need to make it smaller by breaking it into chunks.

And then implement a mechanism to combine the chunks back together because it doesn't exist yet

(&#9583;°&#9633;°)&#9583;&#65077; &#9531;&#9473;&#9531;
 

JeTmAn81

Member
That feeling when you made a data structure too big and need to make it smaller by breaking it into chunks.

And then implement a mechanism to combine the chunks back together because it doesn't exist yet

(&#9583;°&#9633;°)&#9583;&#65077; &#9531;&#9473;&#9531;

Tell us about your data structure
 

Chris R

Member
We all know nobody on Windows knows Powershell.

I've set a few people up at work with some scripts. I won't claim to "know" it, but it wasn't impossible to create a few basic little programs that people in my office use every day to speed up tasks they used to do by hand.
 

vypek

Member
Thank you!

It ended up not being so much an interview as a establishing contact and letting me know that they'll be hiring soon, but not right now. I ended up having to take an aptitude test conducted by another company online (CEB/SHL). It was pretty tough and honestly I don't feel so hot coming off of it, but I imagine most candidates don't and I don't know where they set the bar at. It had a lot of truth tables and conditional logic, and some image flipping problems (unsure where that fits into traditional programming). I'm a programmer that enjoys the safety net of being able to test my logic on the fly with a compiler, so given 3 minutes per question was pretty stressful for me.

Fortunately I prefer this to being hired and then let go later because I'm not suited for the job.

Establishing contacts is good too. Hopefully when they do start hiring you'll get hired then. I feel like most people don't come out of these interviews or tests feeling too hot. I felt I really screwed up when I was doing the whiteboard problem for the company I was working at now.

I wonder how common if at all that people are hired and then let go quickly. I think if you get hired that the company generally has some faith in you and doesn't expect to let you go quickly.

Still, good luck in the future and hope things go your way.
 

Zoe

Member
So the boss came into my office out of the blue and said I need to help come up with a list of requirements for another programming position so I can refocus on something else and the new person could take over what I've been stuck with for months.

Boss: We need another you.
Me: Do you need a programmer or a database person? You realize I've been doing nothing but database stuff for the past 6 months.
Boss: <blank stare> Whatever you do.

Sometimes it sucks having a non-technical boss...
 
Tell us about your data structure

It's a transaction meant to be sent across our applications, and there was a maximum data size no one told me about that no one caught in design review.

There might be something in the code that can deal with receiving multiple transactions of the same type but it isn't a universal thing. It's more of a minor annoyance that can snowball in a project on a tight schedule
 
Hello all

I'm in my second week of an intro to programming class and wondering if I could get some advise on my second assignment. It's pseudo code so it doesn't have to be perfect, but I just want to make sure I'm not making a major mistake. Like should I have brackets before the first while, again at the end and indent everything in between?


print " How many miles does the car have?"
input miles
print "How many years old is car"
input years
while (miles <= 3000)
{
if (years <= 3)
{
print "Offer 80% of the original price"
}
else
{
print "Offer 90% of the original price"
}
}
while (miles > 3000 and < 12000)
{
if (years <= 3)
{
print "Offer 70% of the original price"
}
else
{
print "Offer 90% of the original price"
}
}
while (miles >= 12000 and <= 36000)
{
if (years <= 3)
{
print &#8220;Offer 60% of the original price&#8221;
}
else
{
print &#8220;Offer 80% of the original price&#8221;
}
if (miles > 36000
{
print &#8220;Offer 50% of the original price&#8221;
}

edit-Just thought that I could simplify it some by using while (years <= 3) and having mileage as a sub set of that.
 

Somnid

Member
Hello all

I'm in my second week of an intro to programming class and wondering if I could get some advise on my second assignment. It's pseudo code so it doesn't have to be perfect, but I just want to make sure I'm not making a major mistake. Like should I have brackets before the first while, again at the end and indent everything in between?

While repeats anything between the braces while the condition is true. You'll just endlessly repeat your messages. You either need to vary miles within the loop so it can eventually end or make it an if so it runs once. I'm not sure which is more appropriate.
 

Koren

Member
I'd there's a confusion between while and if.

You use while if you want to *repeat* a set of commands as long as the test following the while is true.

In your example, I don't see why you would need a while (you'll get an infinite loop since miles isn't changing)

I also suspect that some if are inverted, and the <= / < are a bit surprising (although it's syntaxically correct)
 
While repeats anything between the braces while the condition is true. You'll just endlessly repeat your messages. You either need to vary miles within the loop so it can eventually end or make it an if so it runs once. I'm not sure which is more appropriate.

The problem is so that a used car dealership can input the miles and years and it will spit out the appropriate offer. I guess I misunderstood the use of while. Changing the whiles to ifs should work. I originally had it as.

if (miles <= 3000 and years <= 3)
print "Offer"
if (miles <=3000 and years > 3)
print "Offer"

until the end I was just trying to simplify

I'd there's a confusion between while and if.

You use while if you want to *repeat* a set of commands as long as the test following the while is true.

In your example, I don't see why you would need a while (you'll get an infinite loop since miles isn't changing)

I also suspect that some if are inverted, and the <= / < are a bit surprising (although it's syntaxically correct)

Yeah the % don't make sense. The problem is written so that you offer more for an older car, which is irritating. The <= is the way the instructor wants it written.
 

JeTmAn81

Member
It's a transaction meant to be sent across our applications, and there was a maximum data size no one told me about that no one caught in design review.

There might be something in the code that can deal with receiving multiple transactions of the same type but it isn't a universal thing. It's more of a minor annoyance that can snowball in a project on a tight schedule

I wanted more detail than that.

Anyway, sounds like you need an adapter?
 

Koren

Member
The problem is so that a used car dealership can input the miles and years and it will spit out the appropriate offer. I guess I misunderstood the use of while. Changing the whiles to ifs should work. I originally had it as.

if (miles <= 3000 and years <= 3)
print "Offer"
if (miles <=3000 and years > 3)
print "Offer"

until the end I was just trying to simplify
Rightly. But you can nest the ifs :
Code:
if (miles <= 3000) {
    if (years <= 3) {
        print "Offer"
    }
    else
    {
        print "Offer"
    }
}
It's just the keyword that is wrong, everything else is correct...

Yeah the % don't make sense. The problem is written so that you offer more for an older car, which is irritating.
That's strange, but if that's the assignment... I just thought the comparison may have been inverted.

The <= is the way the instructor wants it written.
I'm fine with <=, it's just usually it's something like, for example :

miles <= 3000
miles > 3000 and miles <= 12000
miles > 12000 and miles <= 36000
miles > 36000

Not about the "direction" of the comparisons. Just the fact that I find strange that whether the borders of the interval is included isn't consistent. That's a detail, though.
 
Rightly. But you can nest the ifs :
Code:
if (miles <= 3000) {
    if (years <= 3) {
        print "Offer"
    }
    else
    {
        print "Offer"
    }
}
It's just the keyword that is wrong, everything else is correct...


That's strange, but if that's the assignment... I just thought the comparison may have been inverted.


I'm fine with <=, it's just usually it's something like, for example :

miles <= 3000
miles > 3000 and miles <= 12000
miles > 12000 and miles <= 36000
miles > 36000

Not about the "direction" of the comparisons. Just the fact that I find strange that whether the borders of the interval is included isn't consistent. That's a detail, though.

Cool that makes sense. I have noticed though that sometimes people use the brackets differently. Like in your example it's.

if (miles) {

I've also seen

if (miles)
{

Not sure if there is a difference.
 
Cool that makes sense. I have noticed though that sometimes people use the brackets differently. Like in your example it's.

if (miles) {

I've also seen

if (miles)
{

Not sure if there is a difference.

There's no difference in terms of execution in those two cases, just coding style.
 

vypek

Member
Makes me think of peoples decisions behind their brace style. I'm curious which brace style Programming-GAF uses and why. Just preference or maybe you just stuck to which you learned first?

I like Allman just based off of how clean and organized it looks to me. I know K&R seems to be used quite a lot as well but I feel like I get lost reading it sometimes and have trouble getting used to it.
 
I learned by putting the brace on the same line; only really started putting the brace on a new line when I started my current job when a bunch of the code already does it.

I could go either way; sometimes I prefer a more condensed view especially if the block only has 1/2 statements
 
I format them however is dictated by the coding standard of the project I'm working on. And if it's my own project, I pretty much ignore it and let visual studio auto format my code for me. More important things to worry about.
 

Somnid

Member
In C# I do braces on a separate line because that's the standard style, in Javascript I usually go more compact since ifs/loops/functions always end with one it's not any harder to scan.
 

JesseZao

Member
I put braces on new lines as VS defaults to (Allman). That said, I will just use indentation if using single line conditional blocks. I'm always refactoring to get stuff looking clean and love the ternary operator.

I'm doing a web app rewrite of an old employee and his coding style was horrendous.

Edit: When writing in Java, the IDEs I've used would default to Egyptian style. Didn't bother me then, but I'd probably change it now.

The Clean Code author found that indentation laziness was the number one indicator of bad code throughout his career.
 

Koren

Member
When I am to choose the style, my own style is a mix a K&R, Stroustrup, Egyptian brackets, 1TBS and a couple of personal rules. Usually for readability (utterly subjective), symmetry (In an if/the/else, I want braces on both sides, or neither) and vertical compactness.

For the last reason, I often use
Code:
for (int i=0; i<n; ++i) { sum += tab[i]; }
or, if the line is too long,
Code:
for (int i=0; i<n; ++i)
    { sum += tab[i]; }
instead of
Code:
for (int i=0; i<n; ++i) {
    sum += tab[i];
}
(which would be my style when there's more than a single line)


I don't think it matters, though. Obvioulsy, I stick to the rules in projects. But sometimes it's not easy (GNU style for example). And I really don't like 8-spaces tabs.

The Clean Code author found that indentation laziness was the number one indicator of bad code throughout his career.
Indentation, I can understand, but braces styling, I keep seeing statistical studies that say it doesn't matter at all.
 

Koren

Member
I think I am going to be sick
That's a bit much, no?

I like it that way, and I doubt there's a valid reason to value a style over another beside personal preferences. I'm fine with you not liking it, there's plenlty of styles I don't like myself.

A line that begin with an opening brace is a single line block, since it'll always end with the closing brace at the end of the line. There's really no place for confusion there. So? Why would it be an issue besides habits?


To be more precise, K&R variants usually allow
Code:
for (int i=0; i<n; ++i)
    sum += tab[i];
and
Code:
for (int i=0; i<n; ++i) {
    sum += tab[i];
}

The problem I have with this is that you can't see, by only reading indentation and the beginning of lines, if you'll need a closing brace or not... At least, if the line following a while, an if or a for doesn't begin with a {, I know in my case that I need a } aligned with the for.
 

Makai

Member
As in the language?

Obviously, there's far less issues of indentation and spacing there ;)
Lots of languages use indentation instead of braces. I strongly prefer it. Much more readable and fun to write. Also, no ideological disagreements about brace alignment.

Code:
namespace Project
{
    public static class Math
    {
        public static int Factorial(int n)
        {
            if (n <= 1)
            {
                return 1;
            }
            else
            {
                return n * Factorial(n - 1);
            }
        }
    }
}


Code:
namespace Project
module Math

let rec factorial n =
    match n with
    | 0 | 1 -> 1
    | _ -> n * factorial(n - 1)
 
Top Bottom