• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 13:21
CEST 19:21
KST 02:21
  • 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
[ASL20] Ro24 Preview Pt2: Take-Off0[ASL20] Ro24 Preview Pt1: Runway132v2 & SC: Evo Complete: Weekend Double Feature4Team Liquid Map Contest #21 - Presented by Monster Energy9uThermal's 2v2 Tour: $15,000 Main Event18
Community News
Maestros of The Game—$20k event w/ live finals in Paris24Weekly Cups (Aug 11-17): MaxPax triples again!13Weekly Cups (Aug 4-10): MaxPax wins a triple6SC2's Safe House 2 - October 18 & 195Weekly Cups (Jul 28-Aug 3): herO doubles up6
StarCraft 2
General
What mix of new and old maps do you want in the next 1v1 ladder pool? (SC2) : 2v2 & SC: Evo Complete: Weekend Double Feature Geoff 'iNcontroL' Robinson has passed away The GOAT ranking of GOAT rankings RSL Revival patreon money discussion thread
Tourneys
Maestros of The Game—$20k event w/ live finals in Paris RSL: Revival, a new crowdfunded tournament series Sparkling Tuna Cup - Weekly Open Tournament Monday Nights Weeklies Master Swan Open (Global Bronze-Master 2)
Strategy
Custom Maps
External Content
Mutation # 487 Think Fast Mutation # 486 Watch the Skies Mutation # 485 Death from Below Mutation # 484 Magnetic Pull
Brood War
General
[ASL20] Ro24 Preview Pt2: Take-Off BW General Discussion No Rain in ASL20? Flash On His 2010 "God" Form, Mind Games, vs JD BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[ASL20] Ro24 Group C [ASL20] Ro24 Group B BWCL Season 63 Announcement [CSLPRO] It's CSLAN Season! - Last Chance
Strategy
Simple Questions, Simple Answers Fighting Spirit mining rates [G] Mineral Boosting Muta micro map competition
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread General RTS Discussion Thread Dawn of War IV Path of Exile
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
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread The year 2050 European Politico-economics QA Mega-thread
Fan Clubs
INnoVation Fan Club SKT1 Classic Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2026 Football Thread TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion
World Cup 2022
Tech Support
High temperatures on bridge(s) Gtx660 graphics card replacement Installation of Windows 10 suck at "just a moment"
TL Community
The Automated Ban List TeamLiquid Team Shirt On Sale
Blogs
Evil Gacha Games and the…
ffswowsucks
Breaking the Meta: Non-Stand…
TrAiDoS
INDEPENDIENTE LA CTM
XenOsky
[Girl blog} My fema…
artosisisthebest
Sharpening the Filtration…
frozenclaw
ASL S20 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 3956 users

The Big Programming Thread - Page 137

Forum Index > General Forum
Post a Reply
Prev 1 135 136 137 138 139 1031 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
Hyrule19077 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
Hyrule19077 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
Hyrule19077 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 1031 Next
Please log in or register to reply.
Live Events Refresh
Chat StarLeague
16:00
Chicago LAN Final Day
Razz vs Julia
StRyKeR vs ZZZero
Semih vs TBD
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SteadfastSC 292
ProTech133
SpeCial 109
BRAT_OK 60
JuggernautJason30
EmSc Tv 25
MindelVK 25
StarCraft: Brood War
Britney 41410
Mini 712
firebathero 164
JulyZerg 124
Hyuk 84
Pusan 63
ggaemo 44
Sacsri 36
soO 34
HiyA 16
[ Show more ]
Free 12
Noble 7
Stormgate
BeoMulf146
Dota 2
Gorgc15197
XcaliburYe254
Counter-Strike
fl0m1565
flusha225
Stewie2K124
Heroes of the Storm
Khaldor275
Other Games
gofns8271
FrodaN1488
Beastyqt803
B2W.Neo334
Hui .302
ToD215
KnowMe148
Organizations
Other Games
gamesdonequick675
StarCraft 2
EmSc Tv 25
EmSc2Tv 25
StarCraft: Brood War
CasterMuse 3
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 17 non-featured ]
StarCraft 2
• StrangeGG 44
• LUISG 27
• IndyKCrew
• AfreecaTV YouTube
• sooper7s
• intothetv
• Kozan
• Migwel
• LaughNgamezSOOP
StarCraft: Brood War
• Michael_bg 8
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
League of Legends
• Nemesis4985
Counter-Strike
• Shiphtur151
• imaqtpie143
Other Games
• WagamamaTV439
Upcoming Events
Replay Cast
6h 39m
Afreeca Starleague
16h 39m
Queen vs HyuN
EffOrt vs Calm
Wardi Open
17h 39m
RotterdaM Event
21h 39m
Replay Cast
1d 6h
Afreeca Starleague
1d 16h
Rush vs TBD
Jaedong vs Mong
WardiTV Summer Champion…
1d 17h
Cure vs Classic
ByuN vs TBD
herO vs TBD
TBD vs NightMare
TBD vs MaxPax
PiGosaur Monday
2 days
Afreeca Starleague
2 days
herO vs TBD
Royal vs Barracks
Replay Cast
3 days
[ Show More ]
The PondCast
3 days
WardiTV Summer Champion…
3 days
Replay Cast
4 days
LiuLi Cup
4 days
MaxPax vs TriGGeR
ByuN vs herO
Cure vs Rogue
Classic vs HeRoMaRinE
Cosmonarchy
4 days
OyAji vs Sziky
Sziky vs WolFix
WolFix vs OyAji
BSL Team Wars
5 days
Team Hawk vs Team Dewalt
BSL Team Wars
5 days
Team Hawk vs Team Bonyth
SC Evo League
5 days
TaeJa vs Cure
Rogue vs threepoint
ByuN vs Creator
MaNa vs Classic
[BSL 2025] Weekly
6 days
SC Evo League
6 days
Liquipedia Results

Completed

Jiahua Invitational
uThermal 2v2 Main Event
HCC Europe

Ongoing

Copa Latinoamericana 4
BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Qualifiers
ASL Season 20
CSL Season 18: Qualifier 1
Acropolis #4 - TS1
CSLAN 3
SEL Season 2 Championship
WardiTV Summer 2025
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
BLAST.tv Austin Major 2025

Upcoming

CSL Season 18: Qualifier 2
CSL 2025 AUTUMN (S18)
LASL Season 20
BSL Season 21
BSL 21 Team A
Chzzk MurlocKing SC1 vs SC2 Cup #2
RSL Revival: Season 2
Maestros of the Game
EC S1
Sisters' Call Cup
IEM Chengdu 2025
PGL Masters Bucharest 2025
MESA Nomadic Masters Fall
Thunderpick World Champ.
CS Asia Championships 2025
Roobet Cup 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
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 © 2025 TLnet. All Rights Reserved.