• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 02:51
CET 08:51
KST 16:51
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
HomeStory Cup 28 - Info & Preview11Rongyi Cup S3 - Preview & Info3herO wins SC2 All-Star Invitational14SC2 All-Star Invitational: Tournament Preview5RSL Revival - 2025 Season Finals Preview8
Community News
Weekly Cups (Jan 19-25): Bunny, Trigger, MaxPax win3Weekly Cups (Jan 12-18): herO, MaxPax, Solar win0BSL Season 2025 - Full Overview and Conclusion8Weekly Cups (Jan 5-11): Clem wins big offline, Trigger upsets4$21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7)38
StarCraft 2
General
HomeStory Cup 28 - Info & Preview StarCraft 2 Not at the Esports World Cup 2026 Weekly Cups (Jan 19-25): Bunny, Trigger, MaxPax win Oliveira Would Have Returned If EWC Continued herO wins SC2 All-Star Invitational
Tourneys
HomeStory Cup 28 KSL Week 85 $21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7) OSC Season 13 World Championship $70 Prize Pool Ladder Legends Academy Weekly Open!
Strategy
Simple Questions Simple Answers
Custom Maps
[A] Starcraft Sound Mod
External Content
Mutation # 510 Safety Violation Mutation # 509 Doomsday Report Mutation # 508 Violent Night Mutation # 507 Well Trained
Brood War
General
BW General Discussion Can someone share very abbreviated BW cliffnotes? [ASL21] Potential Map Candidates BGH Auto Balance -> http://bghmmr.eu/ Bleak Future After Failed ProGaming Career
Tourneys
[Megathread] Daily Proleagues Small VOD Thread 2.0 Azhi's Colosseum - Season 2 [BSL21] Non-Korean Championship - Starts Jan 10
Strategy
Zealot bombing is no longer popular? Simple Questions, Simple Answers Current Meta Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Nintendo Switch Thread Battle Aces/David Kim RTS Megathread Path of Exile Mobile Legends: Bang Bang Beyond All Reason
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Mafia Game Mode Feedback/Ideas Vanilla Mini Mafia
Community
General
Magis TV – Easy Way to Stream Movies, TV Shows US Politics Mega-thread Canadian Politics Mega-thread Russo-Ukrainian War Thread European Politico-economics QA Mega-thread
Fan Clubs
The herO Fan Club! The IdrA Fan Club
Media & Entertainment
[Manga] One Piece Anime Discussion Thread
Sports
2024 - 2026 Football Thread
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Let's Get Creative–Video Gam…
TrAiDoS
My 2025 Magic: The Gathering…
DARKING
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2336 users

The Big Programming Thread - Page 137

Forum Index > General Forum
Post a Reply
Prev 1 135 136 137 138 139 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
haduken
Profile Blog Joined April 2003
Australia8267 Posts
Last Edited: 2012-05-16 08:56:15
May 16 2012 08:54 GMT
#2721
Debian or Arch Linux would be my pick.

Debian uses the same package management system as Ubuntu so if you've used to Ubuntu, the learning curve is steady and Debian is used commercially in web servers etc...

With that being said, for learning purposes you can do everything you need Ubuntu as well, what exactly do you find Ubuntu insufficient?

Once you get used to the file system and bash commands and how to source your packages then everything else is a manpage away.
Rillanon.au
Sad[Panda]
Profile Blog Joined January 2009
United States458 Posts
May 16 2012 09:56 GMT
#2722
On May 16 2012 17:54 haduken wrote:
Debian or Arch Linux would be my pick.

Debian uses the same package management system as Ubuntu so if you've used to Ubuntu, the learning curve is steady and Debian is used commercially in web servers etc...

With that being said, for learning purposes you can do everything you need Ubuntu as well, what exactly do you find Ubuntu insufficient?

Once you get used to the file system and bash commands and how to source your packages then everything else is a manpage away.


Like I said I could just be ignorant, for me I feel like I haven't had to do anything I couldn't do in windows in Linux yet which includes installing browsers, eclipse etc. I mean I learned I could sudo apt-get install firefox for firefox but I didn't need to / know to / had to look how to, since it had the Ubuntu market like thing I found the basic things I wanted on Linux (Skype/Firefox/Eclipse). Still trying to get used to the file system just since its not what I am normally used to.
( O.O) ("\(t.t )/") ~ I'm just looking for someone to hug
tofucake
Profile Blog Joined October 2009
Hyrule19192 Posts
May 16 2012 11:42 GMT
#2723
Gentoo, Fedora, Debian, and Ubuntu are rather similar. If you want to learn Linux and C, and I mean really learn them, check out Slackware.
Liquipediaasante sana squash banana
haduken
Profile Blog Joined April 2003
Australia8267 Posts
Last Edited: 2012-05-16 12:29:59
May 16 2012 12:29 GMT
#2724
On May 16 2012 18:56 Sad[Panda] wrote:
Show nested quote +
On May 16 2012 17:54 haduken wrote:
Debian or Arch Linux would be my pick.

Debian uses the same package management system as Ubuntu so if you've used to Ubuntu, the learning curve is steady and Debian is used commercially in web servers etc...

With that being said, for learning purposes you can do everything you need Ubuntu as well, what exactly do you find Ubuntu insufficient?

Once you get used to the file system and bash commands and how to source your packages then everything else is a manpage away.


Like I said I could just be ignorant, for me I feel like I haven't had to do anything I couldn't do in windows in Linux yet which includes installing browsers, eclipse etc. I mean I learned I could sudo apt-get install firefox for firefox but I didn't need to / know to / had to look how to, since it had the Ubuntu market like thing I found the basic things I wanted on Linux (Skype/Firefox/Eclipse). Still trying to get used to the file system just since its not what I am normally used to.


I guess that's a good thing that Ubuntu has come a long way. Try to install something from outside the official repository, there are heaps of programs in the official repository that won't be the latest version etc... Try installing Brood war via WINE.

You won't really learn much until you start breaking things then fixing them lols

But this isn't really learning C though, Linux isn't some scary technical beast, the basics are a bit more advanced compare to Windows but it isn't rocket science.
Rillanon.au
Sad[Panda]
Profile Blog Joined January 2009
United States458 Posts
May 17 2012 05:49 GMT
#2725
On May 16 2012 21:29 haduken wrote:
Show nested quote +
On May 16 2012 18:56 Sad[Panda] wrote:
On May 16 2012 17:54 haduken wrote:
Debian or Arch Linux would be my pick.

Debian uses the same package management system as Ubuntu so if you've used to Ubuntu, the learning curve is steady and Debian is used commercially in web servers etc...

With that being said, for learning purposes you can do everything you need Ubuntu as well, what exactly do you find Ubuntu insufficient?

Once you get used to the file system and bash commands and how to source your packages then everything else is a manpage away.


Like I said I could just be ignorant, for me I feel like I haven't had to do anything I couldn't do in windows in Linux yet which includes installing browsers, eclipse etc. I mean I learned I could sudo apt-get install firefox for firefox but I didn't need to / know to / had to look how to, since it had the Ubuntu market like thing I found the basic things I wanted on Linux (Skype/Firefox/Eclipse). Still trying to get used to the file system just since its not what I am normally used to.


I guess that's a good thing that Ubuntu has come a long way. Try to install something from outside the official repository, there are heaps of programs in the official repository that won't be the latest version etc... Try installing Brood war via WINE.

You won't really learn much until you start breaking things then fixing them lols

But this isn't really learning C though, Linux isn't some scary technical beast, the basics are a bit more advanced compare to Windows but it isn't rocket science.


alright any thing you could recommend me needing/using in Linux to try to get used to dling things out of repository? Maybe something C related or just c00l shi- :3
( O.O) ("\(t.t )/") ~ I'm just looking for someone to hug
icystorage
Profile Blog Joined November 2008
Jollibee19350 Posts
Last Edited: 2012-05-17 09:12:13
May 17 2012 07:21 GMT
#2726
iv been searching the internet but have found nothing related to this =/

can i use a master-slaves with iOS devices?

(one iPhone as master while having multiple iPhones as slaves)

my keywords for the search were "iOS iPhone master slave"

EDIT: finally found what i needed

http://www.macresearch.org/cocoa-scientists-part-xxviii-bonjour-and-how-do-you-do
http://www.macresearch.org/cocoa-scientists-part-xxix-message

incase somebody needs it

EDIT2: ohshit, its for mac =/ i need something like iPhone to iPhone
LiquidDota StaffAre you ready for a Miracle-? We are! The International 2017 Champions!
Carapas
Profile Joined February 2011
Canada242 Posts
Last Edited: 2012-05-22 01:38:54
May 22 2012 01:38 GMT
#2727
Hey guys, i've got a lot of free time this summer, so I decided to learn some languages by myself to be ready for university. Since I already know C and C++, I have decided to learn assembly(preferably MASM) to help me really figure out what is going out when I program something in another language.

So far, all the tutorials I've found are either too short, they doesn't really go far in difficulty or are for experience assembly programmers. So TL, if one of you knows a good ASM tutorial please tell me!
simmion
Profile Joined June 2011
United States34 Posts
May 22 2012 20:29 GMT
#2728
On May 11 2012 13:53 Crazyeyes wrote:
So it's now summer, and as a CS student with zero experience of any sort I figure it'd be nice to get some. Making some money in the meantmie would also be neat.
I've been checking local classifieds and stuff, but am having the common problem of 'MINIMUM 5 YEARS EXPERIENCE.'

Anyways, the few jobs I DO find seem overwhelming and scary. All of them involve things I've never done and therefore do not know how to do. I'm afraid to apply for fear that I do get the job and then find myself lost and overwhelmed.

So I'm here hoping to learn that this is common and that my fears are irrational, I guess.
I just wanna have a compsci job ;_;


It'll be pretty difficult to find summer/internship work as you've stated, the field is rather competitive. My best advice is to look long and hard to find a good company that takes in entry level programmers. I've been working at a company called PTC (www.ptc.com) for 2 years now, they hired me about 3 days after graduating from a state college. They hire a lot of other entry level, fresh graduates at the office that I applied at. so they have a very good training program for bringing in new hires. Thats something that is absolutely invaluable. Instead of being thrown to the wolves a good company will ease you in and provide a strong leadership and support team to get you in, and on the road to learning how to work in a professional programming environment.
"Ricky Bobby" -stephano
simmion
Profile Joined June 2011
United States34 Posts
May 22 2012 21:01 GMT
#2729
On May 14 2012 23:06 heroyi wrote:
whelp I can't figure this out...

I was wondering if someone could help explain to me how to utilize bool in a function form. The reason I ask this is because I am working on this tic tac toe game and am trying to make it so that the game keeps going (asking players to make turns) until it reaches to a halt (three in a row) thus ending the game. I can't figure out how to use the boolean operation to a function form...

Here is the code to help me on:

+ Show Spoiler +


int a = 0;
int b = 0;
int i = 0;

int j = 0;
char tictac[3][3] =
{
{'1','2','3'},
{'4','5','6'},
{'7','8','9'}
};

void board() //intialize board
{
for(i=0;i<3;i++)
{ for(j=0;j<3;j++)
{cout << tictac[i][j] << " " ;}
cout << endl;}
cout << endl;
}


void choice() //to help mark spot for player one
{
if(a == 1)
{ tictac[0][0] = 'X';
board();}

else if(a == 2)
{tictac[0][1] = 'X';
board();}

else if(a == 3)
{tictac[0][2] = 'X';
board();}

else if(a == 4)
{tictac[1][0] = 'X';
board();}

else if(a == 5)
{tictac[1][1] = 'X';
board();}

else if(a == 6)
{tictac[1][2] = 'X';
board();}

else if(a == 7)
{tictac[2][0] = 'X';
board();}

else if(a == 8)
{tictac[2][1] = 'X';
board();}

else if(a == 9)
{tictac[2][2] = 'X';
board();}
}

void choice1() //to help mark spot for player 2
{
if(b == 1)
{tictac[0][0] = 'O';
board();}

else if(b == 2)
{tictac[0][1] = 'O';
board();}

else if(b == 3)
{tictac[0][2] = 'O';
board();}

else if(b == 4)
{tictac[1][0] = 'O';
board();}

else if(b == 5)
{tictac[1][1] = 'O';
board();}

else if(b == 6)
{tictac[1][2] = 'O';
board();}

else if(b == 7)
{tictac[2][0] = 'O';
board();}

else if(b == 8)
{tictac[2][1] = 'O';
board();}

else if(b == 9)
{tictac[2][2] = 'O';
board();}

}



void player1() ]//loop to ask for turn for player 1
{
cout << "Player 1: ";
cin >> a;
while (!cin || a == b) // loop to help catch bad input
{
cout << "choose a different spot: ";
cin.clear();
cin.sync();
cin >> a;
}
choice();
}

void player2() //loop to ask for turn for player 2
{
cout << "Player 2: ";
cin >> b;
while (!cin || a == b) //loop to help catch bad input
{
cout << "choose a different spot: ";
cin.clear();
cin.sync();
cin >> b;
}
choice1();
}



int main()
{

Sleep(2000);
cout << "Lets play tic tac toe between two players" << endl;


for(i=0;i<3;i++) //create board
{for(j=0;j<3;j++)
{cout << tictac[i][j] << " " ;}
cout << endl;}
cout << endl;

Sleep(2000);
cout << "Here is the board. Enter the number to mark your spot." << endl;
cout << "Player 1 is X and player 2 is O." << endl;


cout << "Player 1 goes first. Please enter your number: ";
cin >> a;
choice();
cout << "Player 2: ";
cin >> b;
while (!cin || a == b)
{
cout << "choose a different spot: ";
cin.clear();
cin.sync();
cin >> b;
}
choice1();

[b]//below is the loop/boolean code I am trying to implement but to fail. I have tried different variations and this one here just happens to be the one that I copy and pasted here.[/b]

while(tictac[0][0] == tictac[0][1] != tictac[0][2] || tictac[0][0] == tictac[2][0] != tictac[1][0] || tictac[2][0] == tictac[2][1] != tictac[2][2] || tictac[0][0] != tictac[1][1] == tictac[2][2] || tictac[2][2] != tictac[1][2] == tictac[0][2] )
{player1();
player2();
}


//^^Here I was trying to make it so that as long as three in a row wasn't created then the game would continue in the loop (thus the while loop). However if a three in a row was detected then the statement would become false and would jump out of the loop to "end the game."


{cout << "gg" << endl;} //not the best ending but that isnt the problem.



system("PAUSE");
return 0;


}


appreciate the help
btw fyi: You can ignore some of my coding in the main function (block of code above my comments). I understand it may not be "consistent" but I was more worried on making the code work. Once I can get the whole thing going then I will go around and clean it up a bit to make it nicer.

btw how is my coding "style?" Is there any bad "habits" that I should avoid that is present in my work?
*********


off topic: What situation would call for you to use array over vector? Vectors can do everything an array can but better it seems...is it more efficient to use array on a small memory managment or something?

************

sorry for cluttering :/


the problem with your while statement above is that it lacks parenthesis, I don't even want to think about what sort of results that would come up with.

for the decision making to end the game,you could go with a function that would fire after a play is made, and it would start at each position on the board, and "look" at adjacent squares, if it finds a match, looks at the next square in a straight line and returns a true/false based on whether or not a win condition is found.

Another solution is have a method for each of the possible win conditions (Row 1,2,3 across, Column 1,2,3 down, Cross tL/bR, Cross tR/bL) and call all of those and combine that result to find if there is a win condition met. e.g.

+ Show Spoiler +


while(!gameIsWon())
...

boolean gameIsWon()
{
boolean win = false;
win = rowOneWin();
win = rowTwoWin();
...
return win;
}

boolean rowOneWin()
{
boolean win = false;
if( (tictac[0][0] == tictac[0][1]) && (tictac[0][0] == tictac[0][2]))
win = true;
}

...


you also could easly convert the above to find out who won also by passing in an x and changing the methods to check if each square = the passed in value.


a third, probably best option is, to have a method with nested for loops to check for a win and return t/f the only conditions you can't really check easily in the for is the diagonal wins,

also, your 2 methods for entering in an X or O could be greatly reduced. if you did something like:

+ Show Spoiler +

char PLAYER_ONE = 'x';
char PLAYER_TWO = 'o';
void choice(char mark, int position)
{
switch(position):
case(1)
{
if(tictac[0][0] == "")
tictac[0][0] = mark;
break;
}
/* repeat thru case(9) */
}


/*pseudo */

player one make your choice
get player one input
choice(PLAYER_ONE, choice)
player two make your choice
get player 2 input
choice(PLAYER_TWO, choice)


instead of having the same method twice. pass in the X or O along side the choice.


Hopefully this wasn't too confusing, i kept getting ideas while trying to just answer your question. going to have to go write tic tac toe now, i probably already have one somewhere in my codebase haha.
"Ricky Bobby" -stephano
Toboe
Profile Blog Joined February 2010
United States276 Posts
May 22 2012 21:37 GMT
#2730
On May 11 2012 13:53 Crazyeyes wrote:
So it's now summer, and as a CS student with zero experience of any sort I figure it'd be nice to get some...


I just got a job in a similar situation, and I'd like to share what worked for me. I graduated this month with a mathematics degree, no job experience, and no really applicable courses in comp sci (though the classes I did take in c gave me some great fundamentals). The thing I had that most of the recruiters and hr departments loved, besides the ability to speak in complete sentences, was a list of my independent projects on my resume (including my overlay manager).

In my experience, when teams are looking for entry-level/junior developers, they're looking for someone to raise and groom. They're looking for someone who's willing to learn a technology and who is self-motivated to do so. Having projects you've done on your own will exemplify these traits, even if they're in unrelated technologies to the jobs. I ended up getting 2 technical interviews scheduled every day for the first two weeks I looked, and getting 3 offers by the start of the second week, one of which was too good to pass up. A lot of that volume had to do with me being in the Washington D.C. area, though.

So if you can spare some time to work on side projects that you're really interested in, do it and list them on your resume with all the technologies you used. It helps a lot when you're trying to get into these starting positions.
Immortals are your friend, you can tell by the way they waddle at you
sluggaslamoo
Profile Blog Joined November 2009
Australia4494 Posts
Last Edited: 2012-05-23 13:30:02
May 23 2012 13:23 GMT
#2731
On May 16 2012 21:29 haduken wrote:
Show nested quote +
On May 16 2012 18:56 Sad[Panda] wrote:
On May 16 2012 17:54 haduken wrote:
Debian or Arch Linux would be my pick.

Debian uses the same package management system as Ubuntu so if you've used to Ubuntu, the learning curve is steady and Debian is used commercially in web servers etc...

With that being said, for learning purposes you can do everything you need Ubuntu as well, what exactly do you find Ubuntu insufficient?

Once you get used to the file system and bash commands and how to source your packages then everything else is a manpage away.


Like I said I could just be ignorant, for me I feel like I haven't had to do anything I couldn't do in windows in Linux yet which includes installing browsers, eclipse etc. I mean I learned I could sudo apt-get install firefox for firefox but I didn't need to / know to / had to look how to, since it had the Ubuntu market like thing I found the basic things I wanted on Linux (Skype/Firefox/Eclipse). Still trying to get used to the file system just since its not what I am normally used to.


I guess that's a good thing that Ubuntu has come a long way. Try to install something from outside the official repository, there are heaps of programs in the official repository that won't be the latest version etc... Try installing Brood war via WINE.

You won't really learn much until you start breaking things then fixing them lols

But this isn't really learning C though, Linux isn't some scary technical beast, the basics are a bit more advanced compare to Windows but it isn't rocket science.


@"Like I said I could just be ignorant, for me I feel like I haven't had to do anything I couldn't do in windows in Linux yet which includes installing browsers, eclipse etc."

Install Xmonad, a window manager where everything requires a hotkey or linux command. I'm literally doing software development on linux at 300 apm, flicking between different workspaces, using my keybinds to open new windows and adjust them exactly the way I want, grep, piping |, pstree, pkill, ctrl+shift+r, vim/emacs, all things that really I miss in windows.

Doing everything on Windows is such a chore and takes so long to do anything, even search is about 1000x slower than linux grep or find -iname or locate. You can find any file within your hard-drive within half a second with locate, its practically instant, not even exaggerating on this. It may seem trivial, but when you realise how long you spend searching for files, when you can find it instantly whenever is quite a big deal and that's like 0.0001% of what linux has to offer. Once you understand linux well, doing anything is immediate and executable/findable within half a second. No pointless mouse-clicks or having to traverse through folders. Half the time I'm not even opening files but still working directly on them with linux commands, with <<, cat, head/tail, or piping it somewhere.

Here is the best thing about package managers, you wanna install this window manager. No browser or pointless configuration, just "sudo apt-get install xmonad" that's it, and you can start using it right away.
Come play Android Netrunner - http://www.teamliquid.net/forum/viewmessage.php?topic_id=409008
snively
Profile Blog Joined August 2011
United States1159 Posts
May 28 2012 21:16 GMT
#2732
i have a question. suppose i delcare a class in c++. is there any way to make the variables "read-only" outside of the class, so to speak? as in, functions not part of the class could read the variable, but not change its value.

any help wuold be appreciated.
My religion is Starcraft
Denar
Profile Blog Joined March 2011
France1633 Posts
May 28 2012 21:19 GMT
#2733
On May 29 2012 06:16 snively wrote:
i have a question. suppose i delcare a class in c++. is there any way to make the variables "read-only" outside of the class, so to speak? as in, functions not part of the class could read the variable, but not change its value.

any help wuold be appreciated.


Yes, you make those variables private, and you create for each of them methods that will return their values, but no method to change them.

Even though it requires a bit of work, you can define the behaviour you want for each variable
fabiano
Profile Blog Joined August 2009
Brazil4644 Posts
Last Edited: 2012-05-28 21:21:21
May 28 2012 21:20 GMT
#2734
On May 29 2012 06:16 snively wrote:
i have a question. suppose i delcare a class in c++. is there any way to make the variables "read-only" outside of the class, so to speak? as in, functions not part of the class could read the variable, but not change its value.

any help wuold be appreciated.


Make the class attributes private (or protected) and only create getters.

Example:

class A {
private:
int mAttr1;
public:
int getAttr1();
};


mAttr1 will be readable outside of class A, and you won't be able to change its value.

edit: corrected dat confusing english
"When the geyser died, a probe came out" - SirJolt
tofucake
Profile Blog Joined October 2009
Hyrule19192 Posts
May 28 2012 22:00 GMT
#2735
getters suck
use friend
Liquipediaasante sana squash banana
cowsrule
Profile Joined February 2010
United States80 Posts
Last Edited: 2012-05-29 08:15:49
May 29 2012 08:08 GMT
#2736
On May 29 2012 06:20 fabiano wrote:
Show nested quote +
On May 29 2012 06:16 snively wrote:
i have a question. suppose i delcare a class in c++. is there any way to make the variables "read-only" outside of the class, so to speak? as in, functions not part of the class could read the variable, but not change its value.

any help wuold be appreciated.


Make the class attributes private (or protected) and only create getters.

Example:

class A {
private:
int mAttr1;
public:
int getAttr1();
};


mAttr1 will be readable outside of class A, and you won't be able to change its value.

edit: corrected dat confusing english


Also for more complex types, you should return a const reference to the member variable:


class Data {
private:
int mAttr0[10];
};

class A {
private:
Data mAttr1;
public:
const Data& getAttr1() const { return mAttr1; }
};



getters suck
use friend


Friend classes can break encapsulation by allowing them direct access to the private members of the class bypassing the public interface and potentially breaking the invariants of the friended class. Generally you want to limit the number of paths that update the internal state of your class, allowing unrestricted write access (to the friended class) through friendship does the opposite. While useful in some scenarios, replacing getters/setters with friendship may not be the best idea in all cases.
heishe
Profile Blog Joined June 2009
Germany2284 Posts
Last Edited: 2012-05-29 08:50:42
May 29 2012 08:50 GMT
#2737
Suggesting friends for his problems makes no sense. You'd have to add a friend to the class for every type that wants to access its members, which is one of the least generic and hardest to maintain ways to program imaginable.

Friends suck. They introduce code-level dependencies between classes (the class who befriends another must know it, because you have to actually declare the friend in the header), while not really solving any problems.

The only case where they're actually useful if you purposefully absolutely require that only a specific set of classes must have access to your private data. However, in practice, this should very, very rarely be the case.

If outside classes need to access your private data in its raw form to do stuff with it, there's either no reason to make it private or you're handling your private state in regards to the public interface incorrectly (I think in practice this probably usually means that you've divided responsibilities incorrectly, resulting in the fact that one type of problem needs to access another type of problem's private data because it can not make do with whatever the class provides publicly).

Getters don't suck. Apart from the minimal typing overhead, there's no downside to them. Optimizing them away is one of the most basic optimizations there is, and as such, they're not even slower, since even if you don't mark them as inline, compilers (even GCC which is relatively bad at inlining) will inline them basically all the time, completely removing the cost of a function call.

For data access, usually either make it public, or use getters and(or) setters. Which of the two depends on your problem. If you think that the way of accessing the data in the member is never going to be anything else other than a direct read or write (such as would be the case with matrices or vectors, for example), then simply make them public.
For other cases (where you're not sure, or you already have accessing behavior that is not just read/write) use getters and setters.



If you value your soul, never look into the eye of a horse. Your soul will forever be lost in the void of the horse.
CP`
Profile Joined July 2011
Canada38 Posts
Last Edited: 2012-05-29 11:51:51
May 29 2012 10:06 GMT
#2738
On May 22 2012 10:38 Carapas wrote:
Hey guys, i've got a lot of free time this summer, so I decided to learn some languages by myself to be ready for university. Since I already know C and C++, I have decided to learn assembly(preferably MASM) to help me really figure out what is going out when I program something in another language.

So far, all the tutorials I've found are either too short, they doesn't really go far in difficulty or are for experience assembly programmers. So TL, if one of you knows a good ASM tutorial please tell me!


All of the assembly tutorials are short because other than in class there is a good chance that you're never going to need to know assembly backwards and forwards to write any programs. This is partially due to the fact that its a pain in the ass to get anything really useful done in ASM compared to the other higher level languages but also because the compilers nowadays (at least for C/C++) have been optimized well enough that there are very few times that you're ever going to bust out any inline assembly and have it compile to more efficient machine code than the compiler's code.

Since you're trying to understand what really happens when you are programming it would be good to research materials on the stack (What happens when a function is called? What is stored on the stack? What order are variables and other things stored on the stack? etc.) and the different registers used in the x86 architecture (EAX, EBX, ESP, EBP, .....). Writing some simple ASM programs should be enough to see the concepts that those two things represent in action. But learning ASM so you can write non-trivial programs is most likely going to be unnecessary for you in the long run (ie finding a job).

Chapter 2 of Gray Hat Python has a very nice overview of the stack, and the registers and jumps into a little bit of assembly. That book however is all Python and hacking after the first couple chapters which may or may not pique your interest.

EDIT: Just noticed that the site actually provides chapters 2 and 4 for free (Chapter 2).
ForgottenOne
Profile Joined August 2010
Romania236 Posts
Last Edited: 2012-05-29 10:18:12
May 29 2012 10:14 GMT
#2739
On May 29 2012 07:00 tofucake wrote:
getters suck
use friend


Getters are something omnipresent in all languages and in all classes in all languages and if you read 10 lines of code in any program, you're likely to see a declaration of getters or usage of them. So the first observation, "getters suck" is very bad. Getters are The Way to access properties of an object.

Friend is something specific to C++. If you are not really advanced, don't think about such thing as it's something that's seldom useful and something without which you can write your first 100,000 lines of code. Also, there are languages like Java (which runs on like 1 billion devices), which doesn't even support Friend or something similar. So, I'd recomend against using friends unless you know very very well what are you doing.
Born free, as free as the wind blows...
tofucake
Profile Blog Joined October 2009
Hyrule19192 Posts
May 29 2012 13:59 GMT
#2740
He specifically said he was using C++, and using stuff is (imo) the best way to learn it. And getters do suck. Just because they are prevalent doesn't make them good.
Liquipediaasante sana squash banana
Prev 1 135 136 137 138 139 1032 Next
Please log in or register to reply.
Live Events Refresh
Replay Cast
00:00
Korean StarCraft League #85
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
FoxeR 85
StarCraft: Brood War
Shuttle 959
firebathero 450
Larva 357
EffOrt 298
Shinee 77
IntoTheRainbow 70
Bale 28
soO 27
ToSsGirL 24
Noble 21
[ Show more ]
910 9
Sharp 6
Dewaltoss 1
Dota 2
NeuroSwarm179
League of Legends
JimRising 585
Other Games
summit1g8226
WinterStarcraft536
Happy98
febbydoto30
Organizations
Other Games
gamesdonequick716
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• Berry_CruncH144
• Adnapsc2 5
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Lourlo1321
• Stunt347
Upcoming Events
HomeStory Cup
4h 9m
ShoWTimE vs sOs
Serral vs Reynor
Zoun vs HeRoMaRinE
Clem vs Lambo
OSC
5h 9m
Replay Cast
16h 9m
Replay Cast
1d 16h
Wardi Open
2 days
WardiTV Invitational
3 days
Replay Cast
3 days
The PondCast
4 days
WardiTV Invitational
4 days
Replay Cast
4 days
Liquipedia Results

Completed

Proleague 2026-01-31
OSC Championship Season 13
Underdog Cup #3

Ongoing

CSL 2025 WINTER (S19)
KCM Race Survival 2026 Season 1
Acropolis #4 - TS4
Rongyi Cup S3
HSC XXVIII
Nations Cup 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8

Upcoming

Escore Tournament S1: W7
Escore Tournament S1: W8
Acropolis #4
IPSL Spring 2026
uThermal 2v2 2026 Main Event
Bellum Gens Elite Stara Zagora 2026
LiuLi Cup: 2025 Grand Finals
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League Season 23
ESL Pro League Season 23
PGL Cluj-Napoca 2026
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.