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
peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

I'm still confused about libtoolize. Normally who would generate this libtoolize script and how? Does it need to be specific to the target toolset in any way?

Adbot
ADBOT LOVES YOU

Master_Odin
Apr 15, 2010

My spear never misses its mark...

ladies
Does anyone have code to display a tree (like a binary tree) nicely in HTML/CSS?

I found this answer on SO (http://stackoverflow.com/a/31087670/4616655) which looks nice but breaks if it's a large tree (as it doesn't expand horizontally). An example of what I mean is here: https://jsfiddle.net/ccdq9ran/. Not sure if there's a simple solution to get this to just display horizontally fully always.

Dren
Jan 5, 2001

Pillbug

Jsor posted:

What's the best way to remote edit files? I have some code I cannot run or test locally, due to dependency issues, so my workflow is:

edit -> git commit/push -> git pull from ssh'd terminal window -> run -> watch it crash and then repeat, with increasingly horrible commit messages

I mean, it's a solo project so a silly commit history isn't that much of a problem, it's just a bit inefficient and obnoxious. Using scp seems even more obnoxious. I tried some remote editing Sublime Text plugin, but it's not working well on Windows. MSYS2's version of vim is... not stellar and sometimes has some really bad behavior, and vim isn't really my favorite editor anyway.

libfuse/sshfs

Shaocaholica
Oct 29, 2002

Fig. 5E
How much :effort: would I need to exert to compile the latest rsync from source for a PPC mac running 10.4/10.5?

edit: if that's even possible with the latest.

Shaocaholica fucked around with this message at 05:04 on May 15, 2016

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I'm not 100% sure of what I'ma say here so hopefully someone corrects me as needed.

Your two options are to either compile it on the system you're aiming for or cross-compile from your current, probably x64, system.

Both clang and gcc should build and run fine on PPC OS X 10.4 I would think. You can grab an old Xcode from Apple Developer Downloads if you want, though I guess it's possible latest rsync uses compiler features or a language dialect not available in a compiler that old.

In my experience, cross-compiling is pretty straightforward once you figure out the right set of compiler flags and manage to have the right headers in the correct places.

Finally, Apple mucks with rsync and eventually publishes their changes to the Apple Open Source site, so if you're not using that you should probably use that. My guess is there's some added support for various Mac-specific file system attributes.

In terms of effort, I could see myself blowing an hour or two.

1337JiveTurkey
Feb 17, 2005

First step is to get a version of Xcode for 10.4 from the Apple website. I'm pretty sure it's on developer.apple.com. That'll include all the command line tools you'll need to compile C applications. If you just want rsync, it may include that as well, just an ancient version. If not you can install MacPorts, Fink or whatnot to get a current version compiled from source. Otherwise you can just run the scripts on the source code that you downloaded and it should build.

Shaocaholica
Oct 29, 2002

Fig. 5E

1337JiveTurkey posted:

First step is to get a version of Xcode for 10.4 from the Apple website. I'm pretty sure it's on developer.apple.com. That'll include all the command line tools you'll need to compile C applications. If you just want rsync, it may include that as well, just an ancient version. If not you can install MacPorts, Fink or whatnot to get a current version compiled from source. Otherwise you can just run the scripts on the source code that you downloaded and it should build.

Thanks. I wasn't sure if the prebuilt places would still compile for ppc. And compiling myself I wasn't sure if the old libraries would cause any issues but I guess I can always try.

Edit: oh it looks like macports still supports 10.4 and 10.5. Super.

Shaocaholica fucked around with this message at 20:19 on May 15, 2016

StickFigs
Sep 5, 2004

"It's time to choose."
I have to write UI Specification documents in Microsoft Word file format for the code I do at my job. Right now we use screenshots then a table which describes the controls but for fields with data or headers that change with different contexts or data sets its really hard to get across which control you're talking about in a general way.

Anyways, I am looking for a tool that makes writing UI specifications easier not something that tries to generate them automatically though. I'm thinking a tool that lets you highlight and label controls easily and consistently across a team. Any recommendations?

EDIT: This is the closest thing I've found so far: http://www.screenpresso.com/features/ specifically the screenshot next to "Powerful built-in image editor" with the labels and arrows.

StickFigs fucked around with this message at 15:33 on May 16, 2016

Amberskin
Dec 22, 2013

We come in peace! Legit!

StickFigs posted:

Anyways, I am looking for a tool that makes writing UI specifications easier not something that tries to generate them automatically though. I'm thinking a tool that lets you highlight and label controls easily and consistently across a team. Any recommendations?

Powerpoint?

Seriously, that's what is being used in my company.

This could fit perfectly in the programming horrors thread.

csammis
Aug 26, 2003

Mental Institution
I've used Balsamiq at a previous job, sounds like it would hit the points you've listed

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

StickFigs posted:

Anyways, I am looking for a tool that makes writing UI specifications easier not something that tries to generate them automatically though. I'm thinking a tool that lets you highlight and label controls easily and consistently across a team. Any recommendations?

We just started using Invision, looks promising, allows the designers to do some rudimentary UX as well, as in "if you click this area, go to Screen 1, if this area, Screen 2" etc. Have not used it myself though.

StickFigs
Sep 5, 2004

"It's time to choose."
Balsamiq and Invision look like they could do the job but we don't need the mock-up/UI Designer features.

I downloaded Screenpresso and Greenshot (both free for commercial use) and they're both pretty much what I wanted but Screenpresso is a little bit nicer. The only downside is Screenpresso isn't free if you want ALL the features which we might end up needing but the licenses are super cheap compared to those full-blown UI designer apps.

lunar detritus
May 6, 2009


StickFigs posted:



Anyways, I am looking for a tool that makes writing UI specifications easier not something that tries to generate them automatically though. I'm thinking a tool that lets you highlight and label controls easily and consistently across a team. Any recommendations?

Clarify maybe?

StickFigs
Sep 5, 2004

"It's time to choose."
Back with another UI Specifications question!

After some fiddling with the tools suggested earlier I realized that it would be really neat if I could find a tool that lets you build a "wireframe" mockup of a UI and then generate a specification document from the mockup. Basically I would want to be able to make a mockup and have the tool generate a .DOC or HTML file or something with all the controls in my mockup in a table or something so I can add details to every control about their actions, visibility, etc.

Looking at the more popular tools like Balsamiq Mockups and InVision I don't see that they have a feature like this. Is there something like what I'm looking for out there?

kloa
Feb 14, 2007


Adobe XD (I think it's Experience now)?

StickFigs
Sep 5, 2004

"It's time to choose."

kloa posted:

Adobe XD (I think it's Experience now)?



That looks cool but unfortunately it appears to be Mac only right now.

Uziel
Jun 28, 2004

Ask me about losing 200lbs, and becoming the Viking God of W&W.
I wasn't sure which thread this should be in...but I am looking to play mp4 videos in an html5 video tag or whatever, using some javascript library to make it look like the vimeo player.
The mp4s will be on a public internal network share that's on a different server. Which server does the actual processing and will be impacted by site visitors (internal to company network) playing the videos? The website server, or the file server, or both? Help. I don't want to impact other sites on that web server.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Uziel posted:

I wasn't sure which thread this should be in...but I am looking to play mp4 videos in an html5 video tag or whatever, using some javascript library to make it look like the vimeo player.
The mp4s will be on a public internal network share that's on a different server. Which server does the actual processing and will be impacted by site visitors (internal to company network) playing the videos? The website server, or the file server, or both? Help. I don't want to impact other sites on that web server.

There's not really any processing. The server that the file is located on will need to have the bandwidth used to serve the video.

It's like, if I hotlink an image on https://www.aserversomewhereelse.com right here in this post. SA's servers aren't involved in that at all...https://www.aserversomewherelese.com gets the bandwidth bill.

Uziel
Jun 28, 2004

Ask me about losing 200lbs, and becoming the Viking God of W&W.

Thermopyle posted:

There's not really any processing. The server that the file is located on will need to have the bandwidth used to serve the video.

It's like, if I hotlink an image on https://www.aserversomewhereelse.com right here in this post. SA's servers aren't involved in that at all...https://www.aserversomewherelese.com gets the bandwidth bill.
Gotcha, so if I want to avoid negatively impacting any hosted sites, a simple stand-alone file server should be fine. Thanks!

Kiryen
Feb 25, 2015

I've recently gotten a book on C++ and started teaching myself some of it - I selected C++ because the book itself was written in a very approachable fashion (it's called "C++ without fear") and I did know that C++ is a very low-level language going into it.

At any rate, having messed with it on and off for several months I went ahead and wrote a very simple program that calculates overall GPA. No particular reason for that, other than that it seemed like a decent exercise for testing out my nascent skills. Here is my solution:

code:
// GPAcalculator.cpp : Defines the entry point for the console application.;
// Program requests number of credits earned and grades in those credits and returns a GPA;
// Improvements to be made:  Output data to a text file, including summary of inputs given by the user;
// allow for calculation based on percentage grades rather than letters;
// add summary of grades earned by letter to output;

#include "stdafx.h"
#include <iostream>
#include <cstring>
#include <string>
#include <cctype>
using namespace std;

double grade_values[12]{ 4.0, 3.7, 3.3, 3.0, 2.7, 2.3, 2.0, 1.7, 1.3, 1.0, 0.7, 0.0 }; //standardized values for GPA calculation
string grade_letters[] = { "A", "A-", "B+", "B", "B-", "C+", "C", "C-", "D+", "D", "D-", "F" }; //standardized letter grades
double hours_taken[12]; // receives inputs of hours taken at each letter grade
double total_credits = 0.0; //for keeping track of accumulated credit
double total_hours = 0.0;  //for keeping track of total course hours
double input_hours();
double additional_hours(double total_hours, double total_credits); // for credit hours that received GPA values not corresponding to a letter grade.
string yes = "Y";
string yes_no;
void produce_summary(double total_hours, double total_credits);

int main()
{
   cout << "For each letter grade, enter the total number of hours for courses in which you were awarded that grade." << endl;
   input_hours();
   cout << "Do you need to input any course hours at non-standard GPA values?  Enter Y for 'YES'; any other input for 'NO' to receive an average and input summary." << endl;
   cin >> yes_no;
   if (yes_no == yes) {  //determine if the user needs to input any GPA values that do not correspond to typical letter grade values
      additional_hours(total_hours, total_credits);
   }
   produce_summary(total_hours, total_credits);
    return 0;
}

double input_hours() {  //function asks for hours taken at each letter grade successively
   int counter = 0;
   double temp_credits = 0.0;  //for calculating total points towards GPA prior to averaging
   while (counter <= 11) {
      cout << "Enter the number of course hours completed with a grade of " << grade_letters[counter] << "." << endl;
      cin >> hours_taken[counter];
      total_hours = total_hours + hours_taken[counter]; //keeps track of total course hours completed
      temp_credits = hours_taken[counter] * grade_values[counter];  //calculate credit accumulated for grade most recently input
      total_credits = total_credits + temp_credits; //total accumulated credits prior to averaging
      ++counter;
   }
   return total_credits;
}

double additional_hours(double total_hours, double total_credits) {  // function calculates values for GPAs that do not correspond to typical letter grades
   double nonstandard_value = 0.0;
   double nonstandard_hours = 0.0;
   double nonstandard_product = 0.0;
   cout << "Input the nonstandard GPA value to use for additional hours." << endl;
   cin >> nonstandard_value;
   cout << endl << "Input the number of hours taken for which this GPA was awarded." << endl;
   cin >> nonstandard_hours;
   nonstandard_product = nonstandard_hours * nonstandard_value;
   total_hours = total_hours + nonstandard_hours;
   total_credits = total_credits + nonstandard_product;  //after calculating the credit value for nonstandard grades, add to the total for summary function call
   cout << endl << "Do you have any other nonstandard GPA values to input?  Enter 'Y' for YES, any other input to receive your summary." << endl;
   cin >> yes_no;
   if (yes_no == yes) {  //determine if the user needs to input any more nonstandard GPA values
      additional_hours(total_hours, total_credits);
   }
   else {
      return total_credits;
   }
}

void produce_summary(double total_hours, double total_credits) { // summarizes the total hours taken, credit received, and final GPA
   double average_gpa = total_credits / total_hours;
   cout << endl << "Total number of course hours taken: " << total_hours << endl << "Total credit accumulated: " << total_credits << endl << "Final GPA: " << average_gpa <<endl;
   return;
}
Any general comments on style, efficiency, or how I could have done anything better would be greatly welcome.

b0lt
Apr 29, 2005

Kiryen posted:

Any general comments on style, efficiency, or how I could have done anything better would be greatly welcome.
Here are some comments from scanning the code from top to bottom, organized into things that are debatable and things that aren't. Nitpicks are in plain text, actual problems are bolded. (This is holding it up to a professional standard, so don't feel bad)

I generally prefer <string.h> and <ctype.h> over <cstring> and <cctype>. (because they can do different things, and people basically never want the cfoo variants)
Generally, don't use "using namespace", especially for std.
Be consistent. You declare grade_value with an explicit length, but grade_letters with a deduced length.
Avoid globals. total_credits, total_hours, and yes_no should all be defined in the function that uses them.
Use const. If you declare a global std::string yes = "Y", it could get assigned to accidentally, which will lead to obviously bad things.
Don't construct a string to check for equality against.. if (yes_no == "Y") works just fine. If you want to define a constant somewhere, use #define, (or better if you have C++11, static constexpr char yes[] = "Y".)
Avoid recursion when it doesn't make things easier.
Turn on warnings. additional_hours doesn't return a value if yes_no == "Y".
Don't put return at the end of a void function.
Use for.
Use static for things that you're not exporting outside of that file.

b0lt fucked around with this message at 03:46 on May 20, 2016

Kiryen
Feb 25, 2015

b0lt posted:

Here are some comments from scanning the code from top to bottom, organized into things that are debatable and things that aren't. Nitpicks are in plain text, actual problems are bolded. (This is holding it up to a professional standard, so don't feel bad)

I generally prefer <string.h> and <ctype.h> over <cstring> and <cctype>. (because they can do different things, and people basically never want the cfoo variants)
Generally, don't use "using namespace", especially for std.
Be consistent. You declare grade_value with an explicit length, but grade_letters with a deduced length.
Avoid globals. total_credits, total_hours, and yes_no should all be defined in the function that uses them.
Use const. If you declare a global std::string yes = "Y", it could get assigned to accidentally, which will lead to obviously bad things.
Don't construct a string to check for equality against.. if (yes_no == "Y") works just fine. If you want to define a constant somewhere, use #define, (or better if you have C++11, static constexpr char yes[] = "Y".)
Avoid recursion when it doesn't make things easier.
Turn on warnings. additional_hours doesn't return a value if yes_no == "Y".
Don't put return at the end of a void function.
Use for.
Use static for things that you're not exporting outside of that file.

Thanks!

Only thing I would say in reply is that I have to use the "using namespace std" because I'm using Microsoft Visual Studio since it came free with the book. I know there's more popular tools out there but I haven't really gotten into any of them yet.

Sedro
Dec 31, 2008

Uziel posted:

I wasn't sure which thread this should be in...but I am looking to play mp4 videos in an html5 video tag or whatever, using some javascript library to make it look like the vimeo player.
The mp4s will be on a public internal network share that's on a different server. Which server does the actual processing and will be impacted by site visitors (internal to company network) playing the videos? The website server, or the file server, or both? Help. I don't want to impact other sites on that web server.

The file server reads the video (sequential disk I/O) and streams it over the network (network I/O). The web server streams the video straight from the share to the client (network I/O) without doing any weird on-the-fly transcoding. The client downloads the video (network I/O) and decodes the video (cpu/gpu).

Who does the actual processing? The client.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Kiryen posted:

Thanks!

Only thing I would say in reply is that I have to use the "using namespace std" because I'm using Microsoft Visual Studio since it came free with the book. I know there's more popular tools out there but I haven't really gotten into any of them yet.

You can prepend std:: to anything you're using from std.
std::string, etc.

raminasi
Jan 25, 2005

a last drink with no ice

b0lt posted:

I generally prefer <string.h> and <ctype.h> over <cstring> and <cctype>. (because they can do different things, and people basically never want the cfoo variants)

Can you elaborate on this? I was under the impression that they were identical, except for a handful of environments in which sometimes the latter required namespace qualification while the former didn't.

b0lt
Apr 29, 2005

raminasi posted:

Can you elaborate on this? I was under the impression that they were identical, except for a handful of environments in which sometimes the latter required namespace qualification while the former didn't.

cfoo and foo.h are allowed to be identical, but they're also allowed to differ with respect to where symbols get exported. cfoo is required to export them in the std namespace, foo.h is required to export them in the global namespace, they can both optionally export symbols in the other. (cfoo was, at one point prohibited from exporting in the global namespace until c++11 (or 03? I forget), but that was stupid and impossible to implement because the C++ stdlib is a layer on top of the C library on some platforms (the ones that matter))

In practice, it doesn't matter, but being technically correct is the best kind of correct. (also header names like ccomplex and cctype look silly)

b0lt fucked around with this message at 08:42 on May 20, 2016

nielsm
Jun 1, 2009



Kiryen posted:

Only thing I would say in reply is that I have to use the "using namespace std" because I'm using Microsoft Visual Studio since it came free with the book. I know there's more popular tools out there but I haven't really gotten into any of them yet.

Visual Studio is one of the most popular development environments already. It's also a free download (for personal use) from https://msdn.microsoft.com/ - get the Community Edition.

ToxicFrog
Apr 26, 2008


leper khan posted:

You can prepend std:: to anything you're using from std.
std::string, etc.

You can also just pull in the individual symbols you want, e.g. using std::string; means you can now refer to it as just string but you don't end up with the rest of std all over the place.

Uziel
Jun 28, 2004

Ask me about losing 200lbs, and becoming the Viking God of W&W.

Sedro posted:

The file server reads the video (sequential disk I/O) and streams it over the network (network I/O). The web server streams the video straight from the share to the client (network I/O) without doing any weird on-the-fly transcoding. The client downloads the video (network I/O) and decodes the video (cpu/gpu).

Who does the actual processing? The client.
Great to know, thanks! Do I HAVE to serve the video over HTTP then? I'm getting "Not allowed to load local resource" when pointing to files on a share.

Sedro
Dec 31, 2008

Uziel posted:

Great to know, thanks! Do I HAVE to serve the video over HTTP then? I'm getting "Not allowed to load local resource" when pointing to files on a share.

Well, yeah. Web browsers won't let you serve file:// URIs as a security precaution.

Uziel
Jun 28, 2004

Ask me about losing 200lbs, and becoming the Viking God of W&W.

Sedro posted:

Well, yeah. Web browsers won't let you serve file:// URIs as a security precaution.
OK thank you. I've got it working now!

Kiryen
Feb 25, 2015

nielsm posted:

Visual Studio is one of the most popular development environments already. It's also a free download (for personal use) from https://msdn.microsoft.com/ - get the Community Edition.

I got the community edition - a CD came with the book. I did not know it was popular though; I had been under the impression it was looked-down-upon for some reason.

code:
// GPAcalculator.cpp : Defines the entry point for the console application.;
// Program requests number of credits earned and grades in those credits and returns a GPA;
// Improvements to be made:  Output data to a text file, including summary of inputs given by the user; 
// allow for calculation based on percentage grades rather than letters;
// add summary of grades earned by letter to output;

#include "stdafx.h"
#include <iostream>
#include <cstring>
#include <string>
#include <cctype>
using namespace std;

double total_hours = 0.0;  //for keeping track of total course hours
double input_hours();
double additional_hours(double total_hours, double total_credits); // for credit hours that received GPA values not corresponding to a letter grade.
void produce_summary(double total_hours, double total_credits);

int main()
{
	char yes_no[2];
	double total_credits = 0.0;
	cout << "For each letter grade, enter the total number of hours for courses in which you were awarded that grade." << endl;
	total_credits = input_hours();
	cout << "Do you need to input any course hours at non-standard GPA values?  Enter Y for 'YES'; any other input for 'NO' to receive your summary." << endl;
	cin >> yes_no;
	yes_no[0] = toupper(yes_no[0]);
	if (yes_no[0] == 'Y') {  //determine if the user needs to input any GPA values that do not correspond to typical letter grade values
		total_credits = additional_hours(total_hours, total_credits);
	}
	produce_summary(total_hours, total_credits);
    return 0;
}

double input_hours() {  //function asks for hours taken at each letter grade successively
	int counter = 0;
	double grade_values[12]{ 4.0, 3.7, 3.3, 3.0, 2.7, 2.3, 2.0, 1.7, 1.3, 1.0, 0.7, 0.0 }; //standardized values for GPA calculation
	string grade_letters[12] = { "A", "A-", "B+", "B", "B-", "C+", "C", "C-", "D+", "D", "D-", "F" }; //standardized letter grades
	double hours_taken[12]; // receives inputs of hours taken at each letter grade
	double temp_credits = 0.0;  //for calculating total points towards GPA prior to averaging
	double credits = 0.0; //for keeping track of accumulated credit
	while (counter <= 11) {
		cout << "Enter the number of course hours completed with a grade of " << grade_letters[counter] << "." << endl;
		cin >> hours_taken[counter];
		total_hours = total_hours + hours_taken[counter]; //keeps track of total course hours completed
		temp_credits = hours_taken[counter] * grade_values[counter];  //calculate credit accumulated for grade most recently input
		credits = credits + temp_credits; //total accumulated credits prior to averaging
		++counter;
	}
	return credits;
}

double additional_hours(double base_hours, double base_credits) {  // function calculates values for GPAs that do not correspond to typical letter grades
	double nonstandard_value = 0.0;
	double nonstandard_hours = 0.0;
	double nonstandard_product = 0.0;
	char yes_no[2];
	cout << "Input the nonstandard GPA value to use for additional hours." << endl;
	cin >> nonstandard_value;
	cout << endl << "Input the number of hours taken for which this GPA was awarded." << endl;
	cin >> nonstandard_hours;
	nonstandard_product = nonstandard_hours * nonstandard_value;
	total_hours = base_hours + nonstandard_hours;
	double total_credits = base_credits + nonstandard_product;  //after calculating the credit value for nonstandard grades, add to the total for summary function call
	cout << endl << "Do you have any other nonstandard GPA values to input?  Enter 'Y' for YES, any other input to receive your summary." << endl;
	cin >> yes_no;
	yes_no[0] = toupper(yes_no[0]);
	if (yes_no[0] == 'Y') {  //determine if the user needs to input any more nonstandard GPA values
		return additional_hours(total_hours, total_credits);
	}
	else {
		return total_credits;
	}
}

void produce_summary(double total_hours, double total_credits) { // summarizes the total hours taken, credit received, and final GPA
	double average_gpa = total_credits / total_hours;
	cout << endl << "Total number of course hours taken: " << total_hours << endl << "Total credit accumulated: " << total_credits << endl << "Final GPA: " << average_gpa <<endl;
}
I tried to clean up the program and follow some of the advice given, and here is the improved version (which seems to actually work properly).

I could not figure out how to eliminate total_hours as a global variable though, since it needs to be updated along with the credits that the input_hours function passes back. Is there a way to make a function return more than one result? Would using pointers be a good way to do this?

Also, it was mentioned to use "for"; I imagine in place of "while". What is the reason that "for" is preferable?

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Kiryen posted:

I got the community edition - a CD came with the book. I did not know it was popular though; I had been under the impression it was looked-down-upon for some reason.

Not sure why you'd think that. Visual Studio is basically the standard development environment for C/C++/C# on Windows. There are certainly others but they're not nearly as widely used.

quote:

I could not figure out how to eliminate total_hours as a global variable though, since it needs to be updated along with the credits that the input_hours function passes back. Is there a way to make a function return more than one result? Would using pointers be a good way to do this?

To get multiple return values in C++, you need to put the extra return values into the parameter list for the function, and pass them by reference or by pointer, yes. A common pattern for this is for the function's return value to always be an error code (indicating if something went wrong), and any additional return values are passed by reference, like so:

code:
int myFunc(int param1, double param2, int& ret1, std::string& ret2) {
  if (1 == 0) {
    // Math is broken, world is ending.
    return 17;
  }
  ret1 = 42;
  ret2 = "Hello, world!";
  return 0;
}
And you would call that function like this:

code:
int error, response;
std::string message;
error = myFunc(3, 24.1, response, message);
if (error) {
  std::cerr << "Error calling myFunc: " << error << std::endl;
}

quote:

Also, it was mentioned to use "for"; I imagine in place of "while". What is the reason that "for" is preferable?

It's a legibility thing. Always use the loop construct that best describes what you are doing. You typically use "while" for situations where you may loop indefinitely. If your loop has defined limit conditions (as yours does -- you're looping from 0 to 12) then you should use the for loop so those conditions are readily visible to anyone reading your code.

TooMuchAbstraction fucked around with this message at 19:20 on May 20, 2016

nielsm
Jun 1, 2009



My rule of thumb is, if you're looping over a list or array of things, or something that otherwise looks list-like, use a for loop. In a for loop you start at one fixed point and follow a direct path to another fixed point.

A while loop is instead mostly used when going through a dataset (stream) of unknown size, like reading in a file with an unknown number of elements (such as lines or data-records), or when working towards some kind of convergence, such as some mathematical approximation algorithms. They are also useful for input loops in interactive programs, e.g. asking the user to input a line, validate the input in some way, and then either exit the loop if it's okay, or repeat the loop if the input is invalid.

JawKnee
Mar 24, 2007





You'll take the ride to leave this town along that yellow line

nielsm posted:

They are also useful for input loops in interactive programs, e.g. asking the user to input a line, validate the input in some way, and then either exit the loop if it's okay, or repeat the loop if the input is invalid.

Semi-related to this, I'm wondering about the best way to utilize Try-Catch blocks in such a way that if an operation throws an exception, the operation can be retried. Is it bad form to declare a variable outside the Try-Catch block's scope indicating either a boolean success/fail outcome or a simple counter if you want to limit the number of retries to a hard amount - and then put the whole block inside a loop?

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

JawKnee posted:

Semi-related to this, I'm wondering about the best way to utilize Try-Catch blocks in such a way that if an operation throws an exception, the operation can be retried. Is it bad form to declare a variable outside the Try-Catch block's scope indicating either a boolean success/fail outcome or a simple counter if you want to limit the number of retries to a hard amount - and then put the whole block inside a loop?

I'd just make a loop (either a "while (true)" or a "for int numAttempts = 0; numAttempts < MAX_RETRIES; ++numAttempts)", and break out of the loop on success. For example:

code:
while (true) {
  try {
    somethingThatFails();
    break;
  }
  catch (Exception e) {
    // Try again
  }
}

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

JawKnee posted:

Semi-related to this, I'm wondering about the best way to utilize Try-Catch blocks in such a way that if an operation throws an exception, the operation can be retried. Is it bad form to declare a variable outside the Try-Catch block's scope indicating either a boolean success/fail outcome or a simple counter if you want to limit the number of retries to a hard amount - and then put the whole block inside a loop?

Not necessarily bad form, sometimes that's necessary. It could be bad if the try-catch operation is real costly or something, so don't be careless about it, but should be fine.

Pretty much any program which attempts to make a network connection is going to do something like

while(attempts < TIMEOUT){
try
catch
}

and then have some resolution where if you hit the TIMEOUT then you throw up a warning message saying "error, could not connect to server" or whatever.

weird
Jun 4, 2012

by zen death robot

TooMuchAbstraction posted:

Not sure why you'd think that. Visual Studio is basically the standard development environment for C/C++/C# on Windows. There are certainly others but they're not nearly as widely used.

it took it over a decade to support c99 at all and it still doesn't support all of it

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Kiryen posted:

I got the community edition - a CD came with the book. I did not know it was popular though; I had been under the impression it was looked-down-upon for some reason.

Well it's a Windows-only product from Microsoft, so neckbeards will automatically look down on it regardless of merit.

Adbot
ADBOT LOVES YOU

Kiryen
Feb 25, 2015

TooMuchAbstraction posted:

Not sure why you'd think that. Visual Studio is basically the standard development environment for C/C++/C# on Windows. There are certainly others but they're not nearly as widely used.

Because when I first brought up that I wanted to teach myself some C++ and had bought a book that came with a free copy of it elsewhere, I got a bunch of responses with various other things people seemed to think I should be using instead such as cygwin and a few others. I got the impression it was unpopular.

It really didn't seem important to me though; at this point the programs I'm writing are so simple and basic that I don't see why it would matter. They're entirely for learning purposes.

Plorkyeran posted:

Well it's a Windows-only product from Microsoft, so neckbeards will automatically look down on it regardless of merit.

I guess I should have suspected as much.

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