Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
duck monster
Dec 15, 2004

FamDav posted:

Awesome post. You should write for an MRA newsletter.

Yeah , probably not the best way of putting it. Fair point.

Adbot
ADBOT LOVES YOU

UnfurledSails
Sep 1, 2011

I'm an undergrad on a systems track and I've never done anything besides assignments and projects for classes (all of them in either C or C++11). I'm about to finish a class on operating systems implementing Pintos, and while it's fun and challenging, I have zero ideas about what I can do to feel less worthless as a programmer in the real world. Any advice?

FamDav
Mar 29, 2008

UnfurledSails posted:

I'm an undergrad on a systems track and I've never done anything besides assignments and projects for classes (all of them in either C or C++11). I'm about to finish a class on operating systems implementing Pintos, and while it's fun and challenging, I have zero ideas about what I can do to feel less worthless as a programmer in the real world. Any advice?

get an internship.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

UnfurledSails posted:

I'm an undergrad on a systems track and I've never done anything besides assignments and projects for classes (all of them in either C or C++11). I'm about to finish a class on operating systems implementing Pintos, and while it's fun and challenging, I have zero ideas about what I can do to feel less worthless as a programmer in the real world. Any advice?

Find something interesting on GitHub and fix an outstanding task. Working in other people's code is an important skill, as is going through code review. The Awful iOS app could be a good place if you're into that.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
jesus, shrughes has a lot of alt accounts

shrughes
Oct 11, 2008

(call/cc call/cc)
What. How many do I have?

FamDav
Mar 29, 2008
tbf if you want to work on a good app you should probably avoid awful

Dren
Jan 5, 2001

Pillbug

shrughes posted:

What. How many do I have?

I'm beginning to think suspicious dish may be a gimmick account and announcing suspicions of people having alt accounts is the gimmick.

WHERE MY HAT IS AT
Jan 7, 2011
Suspicious dish is shrughes antagonizing himself :tinfoil:

shrughes
Oct 11, 2008

(call/cc call/cc)
My alt account is sarehu FYI. Lost its password years ago.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

FamDav posted:

tbf if you want to work on a good app you should probably avoid awful

Working on good code isn't really the norm, honestly even for me dealing with my own previous stuff. Builds character, or something.

Tip, though: if you see pthread_* just back away. Life's too short for raw shared-state multithreading.

shrughes
Oct 11, 2008

(call/cc call/cc)
code:
$ ack pthread_ src | wc -l
102
Yikes.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

shrughes posted:

code:
$ ack pthread_ src | wc -l
102
Yikes.

Yeah, it's probably too late for you, and someone has to do the dirty work, but if you're looking for something to get started on raw POSIX threading is not a sign of joy. Don't get me wrong, I've done my time (even with linuxthreads, may it rest in agony), I just don't wish it on people. Too many guns for so few feet.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
I've been working primarily in C89 on a variety of embedded platforms for about three years now, and I want to pick up modern C++ for more "normal" systems programming; I haven't touched C++ since before the C++11 standard came out, and I'm rusty in general. What's the best reading to help me quickly reacquaint myself with the joys of RAII and other C++ distinctives?

xgalaxy
Jan 27, 2004
i write code

Otto Skorzeny posted:

I've been working primarily in C89 on a variety of embedded platforms for about three years now, and I want to pick up modern C++ for more "normal" systems programming; I haven't touched C++ since before the C++11 standard came out, and I'm rusty in general. What's the best reading to help me quickly reacquaint myself with the joys of RAII and other C++ distinctives?

http://www.amazon.com/Primer-5th-Edition-Stanley-Lippman/dp/0321714113

duck monster
Dec 15, 2004

UnfurledSails posted:

I'm an undergrad on a systems track and I've never done anything besides assignments and projects for classes (all of them in either C or C++11). I'm about to finish a class on operating systems implementing Pintos, and while it's fun and challenging, I have zero ideas about what I can do to feel less worthless as a programmer in the real world. Any advice?

Most professional programmers are garbage too. If you can write code thats clean, concise, tests well and neatly encapsulates what its supposed to do with minimal cruft and maximal safety, your already doing more than most professionals in the field.

In short: Don't worry about it, just try and get in the door. Incidently the way I got into programming was offering myself for "work experience" to places that didn't actually do internships. First place I contacted , the guy said "I like your ambition kid" and gave me an actual job with pay. Granted it involved maintaining horrifying old COBOL code, but hey, it was the 90s and I had to start somewhere.

HootTheOwl
May 13, 2012

Hootin and shootin
I'm having issues with cin.get() waiting for inputs. Can someone explain why it goes to infinite?

I have the following loop:

code:
while (true)
 {
	cout << "Enter stuff (use ! to quit):" << endl;
	cin.get(stuff, 100);
	if (stuff [0] == '!')
	break;
}
The first time the loop runs, everything is ok. If I enter '!' it'll break like I want but if I put in anything else it just goes infinite.
How do I get it to let me enter a new input each time the loop runs?

Scuzzywuffit
Feb 5, 2012

HootTheOwl posted:

I'm having issues with cin.get() waiting for inputs. Can someone explain why it goes to infinite?

I have the following loop:

code:
while (true)
 {
	cout << "Enter stuff (use ! to quit):" << endl;
	cin.get(stuff, 100);
	if (stuff [0] == '!')
	break;
}
The first time the loop runs, everything is ok. If I enter '!' it'll break like I want but if I put in anything else it just goes infinite.
How do I get it to let me enter a new input each time the loop runs?

When the user presses the enter key, a new line (\n) character is added to cin. cin.get() sees this newline and terminates the string, but doesn't actually remove it from the input buffer. Each successive call to cin.get() sees this newline and immediately returns, hence your infinite loop. You'll have to remove it yourself, like so:
code:
cin.ignore(numeric_limits<streamsize>::max(), '\n');
This removes as many characters from cin as it could possibly contain, stopping when it hits a newline character. To use numeric_limits, you'll also have to #include <limits>. If you don't want to do that, you could also just enter a large integer (e.g. 100) as the first argument.

Does that make sense?

Scuzzywuffit fucked around with this message at 08:15 on Mar 8, 2014

HootTheOwl
May 13, 2012

Hootin and shootin

Scuzzywuffit posted:

When the user presses the enter key, a new line (\n) character is added to cin. cin.get() sees this newline and terminates the string, but doesn't actually remove it from the input buffer. Each successive call to cin.get() sees this newline and immediately returns, hence your infinite loop. You'll have to remove it yourself, like so:
code:
cin.ignore(numeric_limits<streamsize>::max(), '\n');
This removes as many characters from cin as it could possibly contain, stopping when it hits a newline character. To use numeric_limits, you'll also have to #include <limits>. If you don't want to do that, you could also just enter a large integer (e.g. 100) as the first argument.

Does that make sense?
Thank you!
It makes sense. Somewhat.
If I understand you: The user's input is finalized when they enter the '\n' (return key). The cin.get() reads and accepts everything up to the '\n'. It leaves the '\n' as an input so every time my loop ran it would have the '\n' still being inputted thus causing my loop to repeat forever.
So I took your advice on cin.ignore and rewrote my code:
code:
while (true)
 {
	cout << "Enter stuff (use ! to quit):" << endl;
	cin.get(stuff, 100);
	if (stuff [0] == '!')
	break;
	cin.ignore(100, '\n');
}
Which now works exactly the way I want it to (thank you, again) with one exception: If I put nothing as my input it will again loop to infinity. Is it doing the same thing with the floating '\n' input as it did before? If so why is it not being ignored? Could it have to do with it being an invalid input for the variable char stuff?

bobua
Mar 23, 2003
I'd trade it all for just a little more.

Is there some sort of console enhancement library for windows that's awesome? I do a lot of debugging out to the console as I'm learning and tinkering and it seems like simple things like rewriting lines instead of new line\scrolling requires way too much code. Simple stuff like changing the text color would be nice.

Xerophyte
Mar 17, 2008

This space intentionally left blank

bobua posted:

Is there some sort of console enhancement library for windows that's awesome? I do a lot of debugging out to the console as I'm learning and tinkering and it seems like simple things like rewriting lines instead of new line\scrolling requires way too much code. Simple stuff like changing the text color would be nice.

Console2 and ConEmu wrap cmd (and other consoles) to provide some better command entry and text selection, the ability to change colors and the like. How awesome they are is debatable, they're just wrappers and can't change the underlying behavior.

If you need more you'll need to look into using some other command line interpreter like powershell or take command. Personally I'm a big baby and settle for just running Console2 over cmd for my windows shell needs but YMMV.


Well, I totally misunderstood your meaning and should learn to read. :suicide:

Xerophyte fucked around with this message at 21:44 on Mar 8, 2014

bobua
Mar 23, 2003
I'd trade it all for just a little more.

I'm probably not explaining it really well. Right now, if I'm trying to output the state of a variable I can just do cout << i; over and over again, but if I want to keep the state of i on the top left corner of the console at all times there is a ridiculous amount of code needed.


I guess I'm looking for a middle ground between learning one of c++'s gui libraries and just outputing to the console.

GeneralZod
May 28, 2003

Kneel before Zod!
Grimey Drawer

HootTheOwl posted:


Which now works exactly the way I want it to (thank you, again) with one exception: If I put nothing as my input it will again loop to infinity. Is it doing the same thing with the floating '\n' input as it did before? If so why is it not being ignored? Could it have to do with it being an invalid input for the variable char stuff?

Sort of - it's actually because no characters were read, because the very first character is a "\n". In this situation, according to the docs, get(...) will set the failbit of cin internally and after that (until the state is clear'd) get(...) and ignore(...) won't work, so there'll be an infinite loop.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

bobua posted:

I'm probably not explaining it really well. Right now, if I'm trying to output the state of a variable I can just do cout << i; over and over again, but if I want to keep the state of i on the top left corner of the console at all times there is a ridiculous amount of code needed.


I guess I'm looking for a middle ground between learning one of c++'s gui libraries and just outputing to the console.
One possible middle ground is to use ANSI escape sequences, something like
code:
#define ANSIESCAPE_REPOSITION "\0x1b[%d;%dH"
printf(ANSIESCAPE_REPOSITION "Your string.", y, x);
But using a decent library will automatically do stuff like making it so you're not outputting this poo poo to a file if stdout has been redirected to a non-interactive, so is probably a better bet.

If it's just for your own use though, ANSI escape sequences are convenient.

Edit: corrected the order of x and y.

roomforthetuna fucked around with this message at 20:27 on Mar 8, 2014

nielsm
Jun 1, 2009



bobua posted:

Is there some sort of console enhancement library for windows that's awesome? I do a lot of debugging out to the console as I'm learning and tinkering and it seems like simple things like rewriting lines instead of new line\scrolling requires way too much code. Simple stuff like changing the text color would be nice.

Are you really sure this is what you want?
Have you looked into what your debugger can do?

bobua
Mar 23, 2003
I'd trade it all for just a little more.

roomforthetuna posted:

ANSI escape sequences

Thanks, I'll play with this.

nielsm posted:

Are you really sure this is what you want?
Have you looked into what your debugger can do?

No, definitely not sure. But I do need the info output while compiled, ie my program has a 'debug mode' that outputs the data i normally wouldn't need to see.

hooah
Feb 6, 2006
WTF?
I'm working on a project to print, simplify, and evaluate logical expressions. Printing and evaluating is easy, but my partner and I are stuck on the simplification part. In the project description, we're provided with a list of 16 axioms that can help simplify expressions with an undefined component (e.g. x AND false simplifies to false). I think creating a big long list of if/else blocks would work, but if there's a better way, could someone help point us in that direction?

Scaevolus
Apr 16, 2007

hooah posted:

I'm working on a project to print, simplify, and evaluate logical expressions. Printing and evaluating is easy, but my partner and I are stuck on the simplification part. In the project description, we're provided with a list of 16 axioms that can help simplify expressions with an undefined component (e.g. x AND false simplifies to false). I think creating a big long list of if/else blocks would work, but if there's a better way, could someone help point us in that direction?
It depends on how the expressions are represented.

Assuming you have a tree structure, and an expression like x AND (False AND y) could be constructed something like AndOp(Var("x"), AndOp(Literal(false), Var("y")), you could write a structural matching/replacement function, and then have all your axioms as data:

code:
Sometype patterns[][] = {
   { AndOp(Literal(false), Var("x")), 
     Literal(false) },
   { NotOp(AndOp(Var("x"), Var("y")), 
     OrOp(NotOp(Var("x")), NotOp(Var("y")) },
   ...
}

hooah
Feb 6, 2006
WTF?

Scaevolus posted:

It depends on how the expressions are represented.

Assuming you have a tree structure, and an expression like x AND (False AND y) could be constructed something like AndOp(Var("x"), AndOp(Literal(false), Var("y")), you could write a structural matching/replacement function, and then have all your axioms as data:

code:
Sometype patterns[][] = {
   { AndOp(Literal(false), Var("x")), 
     Literal(false) },
   { NotOp(AndOp(Var("x"), Var("y")), 
     OrOp(NotOp(Var("x")), NotOp(Var("y")) },
   ...
}

:psyduck: Ok, yeah, expressions are conceptually represented by a tree, but because they're all in the same class hierarchy, not because they're in a data structure (although it seems you meant the classes, rather than the expressions being in a tree data structure). However, I don't understand your code. What is going on with the double empty square brackets?

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

hooah posted:

However, I don't understand your code. What is going on with the double empty square brackets?

He's creating a 2-dimensional array and initializing it.

Scaevolus
Apr 16, 2007

hooah posted:

:psyduck: Ok, yeah, expressions are conceptually represented by a tree, but because they're all in the same class hierarchy, not because they're in a data structure (although it seems you meant the classes, rather than the expressions being in a tree data structure). However, I don't understand your code. What is going on with the double empty square brackets?
The expressions aren't stored in a tree data structure? That's odd.

patterns is an example of how you might have an array to perform a structural find/replace. These are the axioms represented:
code:
False & X => False
!(X & Y) => !X | !Y

BirdOfPlay
Feb 19, 2012

THUNDERDOME LOSER
How do you mean their in the same class hierarchy? Do you have something like this?
code:
class OpClass{
   OpClass *left;
   OpClass *right;
   ...
}
Cause that would be a tree. If not, how do you mean? Do you have them in a stack in reverse Hungarian Polish?

As to your original question, it's more towards doing the checks in an intelligent fashion and only doing the checks when appropriate.

nielsm
Jun 1, 2009



hooah posted:

:psyduck: Ok, yeah, expressions are conceptually represented by a tree, but because they're all in the same class hierarchy, not because they're in a data structure (although it seems you meant the classes, rather than the expressions being in a tree data structure). However, I don't understand your code. What is going on with the double empty square brackets?

If your representation is based around polymorphism, with having a base ExpressionElement (or whatever) class which might have specializations such as AndExpression, which then in turn holds its own children (which would also be instances of ExpressionElement classes), then you could have each class know how it might simplify.
Something like virtual ExpressionElement* Simplify() const. That would return a possible replacement expression for that element. For instance, calling it on an AndExpression would have the AndExpression first simplify its own two arguments, and if one of them simplifies to (or is) a literal ConstantFalseExpression then the entire AndExpression simplifies to a ConstantFalseExpression.
Effectively, calling Simplify() on a (sub-)expression will produce a new expression with equivalent truth value.
But making this deal with all sorts of cases could get ugly, e.g. I can't think of a good way to make it deal with (a OR b) AND b, which should simplify to just b but requires knowledge of the entire expression tree to derive.

hooah
Feb 6, 2006
WTF?

BirdOfPlay posted:

How do you mean their in the same class hierarchy? Do you have something like this?
code:
class OpClass{
   OpClass *left;
   OpClass *right;
   ...
}
Cause that would be a tree. If not, how do you mean? Do you have them in a stack in reverse Hungarian Polish?

As to your original question, it's more towards doing the checks in an intelligent fashion and only doing the checks when appropriate.

nielsm posted:

If your representation is based around polymorphism, with having a base ExpressionElement (or whatever) class which might have specializations such as AndExpression, which then in turn holds its own children (which would also be instances of ExpressionElement classes), then you could have each class know how it might simplify.
Something like virtual ExpressionElement* Simplify() const. That would return a possible replacement expression for that element. For instance, calling it on an AndExpression would have the AndExpression first simplify its own two arguments, and if one of them simplifies to (or is) a literal ConstantFalseExpression then the entire AndExpression simplifies to a ConstantFalseExpression.
Effectively, calling Simplify() on a (sub-)expression will produce a new expression with equivalent truth value.
But making this deal with all sorts of cases could get ugly, e.g. I can't think of a good way to make it deal with (a OR b) AND b, which should simplify to just b but requires knowledge of the entire expression tree to derive.

nielsm has it right; the expressions are all part of a composite polymorphism tree, with Expression, Negate, Literal, BinaryExpression, etc. Since the point of this project is to use the Composite and Visitor patterns, we're pretending like we already had completed the Expression classes, and now we want to do operations on them, like print, evaluate, and simplify, which are Visitors. I think this requirement precludes doing Simplify() in each class. I think I understand the 2-dimensional array that Scaevolus was talking about, so I'll look into going that route. Thanks, guys!

crazypenguin
Mar 9, 2005
nothing witty here, move along
I don't think there's any need for an array at all?

If you've got 15 simplification rules and like 5 subtypes of expression, that's and average of 3 things to go look for on each method in the visitor. I have no idea why you think this is ugly or too much for a method?

Are you forgetting that in each visitor method you know what the root of that subtree is? Like, you don't need to check the OR rules in "visitAndExpr".

Scaevolus
Apr 16, 2007

crazypenguin posted:

I don't think there's any need for an array at all?
There's not, but writing code to match each expression can be more error prone than writing a generic matching function and defining the patterns as data.

hooah
Feb 6, 2006
WTF?
So we've tried going the non-array route, but it's gotten ugly quickly (as in, using typeid()). We added a Var class that derives from Exp and changed the Literal class to derive from Variable. I've done the SimplificationVisitor methods for visiting Literal and Negate classes (easy), and have been hacking away at the visitAnd method for a day or so now, and it doesn't seem to be going too well. If I zipped up the thing and threw it up on Dropbox, would anyone be willing to help us straighten this project out off the forums? I'd love to go to the TA, but he won't help with code-specific things, only conceptual issues.

crazypenguin
Mar 9, 2005
nothing witty here, move along
The hierarchy should almost certainly be flat. And there's no way constants as a subclass of variables makes sense even if it wasn't flat.

And you'll probably want helper visitors. Consider writing a "constantValue" visitor that returns an enum of NONCONST, CONST_TRUE, CONST_FALSE. Or something like that. (perhaps two: "isConstant" and "constantValue" that returns a boolean.) Once you have this, there's probably no reason you'd ever need to ask specifically what class a child tree is rooted with.

edit: also, I'd say your "coding issues" are stemming from some conceptual problems here, so asking the TA is probably appropriate.

hooah
Feb 6, 2006
WTF?

crazypenguin posted:

The hierarchy should almost certainly be flat. And there's no way constants as a subclass of variables makes sense even if it wasn't flat.

And you'll probably want helper visitors. Consider writing a "constantValue" visitor that returns an enum of NONCONST, CONST_TRUE, CONST_FALSE. Or something like that. (perhaps two: "isConstant" and "constantValue" that returns a boolean.) Once you have this, there's probably no reason you'd ever need to ask specifically what class a child tree is rooted with.

edit: also, I'd say your "coding issues" are stemming from some conceptual problems here, so asking the TA is probably appropriate.

What do you mean by a flat hierarchy? We're required to use the Composite Pattern for the expression stuff.

What are helper visitors? I also don't know about enums :/

Adbot
ADBOT LOVES YOU

crazypenguin
Mar 9, 2005
nothing witty here, move along

hooah posted:

What do you mean by a flat hierarchy? We're required to use the Composite Pattern for the expression stuff.

What are helper visitors? I also don't know about enums :/

Flat hierarchy means everything should derive from Exp. Nothing deriving from other things that derive from Exp.

I'm not sure what the composite pattern is, so perhaps they're making you do something that makes things hard for no reason.

Helper visitor is just another visitor, like the ones I suggested. If you haven't done enums, then writing the two I suggested that just return booleans works too.

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