• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 12:31
CET 18:31
KST 02:31
  • 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
RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3RSL Season 3: RO16 results & RO8 bracket13
StarCraft 2
General
Chinese SC2 server to reopen; live all-star event in Hangzhou Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced Weekly Cups (Nov 24-30): MaxPax, Clem, herO win SC2 Proleague Discontinued; SKT, KT, SGK, CJ disband
Tourneys
Sparkling Tuna Cup - Weekly Open Tournament RSL Offline Finals Info - Dec 13 and 14! StarCraft Evolution League (SC Evo Biweekly) RSL Offline FInals Sea Duckling Open (Global, Bronze-Diamond)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation
Brood War
General
BW General Discussion Which season is the best in ASL? Data analysis on 70 million replays BGH Auto Balance -> http://bghmmr.eu/ [ASL20] Ask the mapmakers — Drop your questions
Tourneys
[Megathread] Daily Proleagues [BSL21] RO16 Group D - Sunday 21:00 CET [BSL21] RO16 Group A - Saturday 21:00 CET [BSL21] RO16 Group B - Sunday 21:00 CET
Strategy
Current Meta Game Theory for Starcraft How to stay on top of macro? PvZ map balance
Other Games
General Games
Stormgate/Frost Giant Megathread ZeroSpace Megathread Nintendo Switch Thread The Perfect Game 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
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Mafia Game Mode Feedback/Ideas TL Mafia Community Thread
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine The Big Programming Thread Artificial Intelligence Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Where to ask questions and add stream? The Automated Ban List
Blogs
Physical Exertion During Gam…
TrAiDoS
James Bond movies ranking - pa…
Topin
Thanks for the RSL
Hildegard
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1458 users

The Big Programming Thread - Page 272

Forum Index > General Forum
Post a Reply
Prev 1 270 271 272 273 274 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.
tec27
Profile Blog Joined June 2004
United States3702 Posts
Last Edited: 2013-03-18 00:37:12
March 18 2013 00:35 GMT
#5421
On March 18 2013 09:17 CecilSunkure wrote:
Show nested quote +
On March 18 2013 09:00 MiyaviTeddy wrote:
Thanks alot Abductedonut & Morfildur

The last few topics I'm still really confused about is:
-Inheritance
-Virtual functions
-Pure virtual
-Abstract classes

any examples or primers would be greatly appreciated! and this is helping me towards finishing my assignment.

These are all related to one another quite heavily.

Inheritance lets you stick one object inside of another completely. Here's a slideshow I made talking about inheritance in C. This is almost exactly like what happens in C++, but it's important to know how to do it (and actually do it yourself) in C first, in my opinion. Read the pdf to understand: what inheritance is, and why it's useful.

The pdf also covers virtual functions and how to implement them.

A pure virtual is a function that must be overridden when a class derives from a type. The compiler will complain if you don't. That's all. This is good for enforcing interfaces.

An abstract class is type that is designed to only be used as a base for derivation. Again, a good example (the only good one I know) is for interfaces.

If you're confused on what an interface is: it is just a set of functions to call. If I employ an interface, then other objects can treat me as if I employ this interface. For example say we make an object to resemble a duck. We have an interface for quacking and swimming. Other code portions can call my quack and swim functions upon me, without knowing about the rest of what I am so long as I employ the duck interface. This is actually referred to as "duck-typing".

That's not the definition of duck typing. Duck typing refers to a style of type system that derives its type information from the interface an object exposes rather than from a inheritance tree that was explicitly laid out. It is common in dynamic languages (Javascript, Ruby, Python, PHP) but can also exist in statically typed languages (Go uses a form of duck typing, for instance). What you described is simply 'polymorphism'.

Also, I don't think understanding how to implement inheritance in C is at all necessary and most definitely overkill for understanding how inheritance, virtual functions, and abstract classes work. The vast majority of programmers likely have no idea how vtables work (and there are very few times where knowing such information will actually matter). Telling someone who is having their first foray into OO to learn all of that stuff is bordering on sadistic.
Can you jam with the console cowboys in cyberspace?
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
Last Edited: 2013-03-18 00:42:03
March 18 2013 00:38 GMT
#5422
On March 18 2013 09:35 tec27 wrote:
Show nested quote +
On March 18 2013 09:17 CecilSunkure wrote:
On March 18 2013 09:00 MiyaviTeddy wrote:
Thanks alot Abductedonut & Morfildur

The last few topics I'm still really confused about is:
-Inheritance
-Virtual functions
-Pure virtual
-Abstract classes

any examples or primers would be greatly appreciated! and this is helping me towards finishing my assignment.

These are all related to one another quite heavily.

Inheritance lets you stick one object inside of another completely. Here's a slideshow I made talking about inheritance in C. This is almost exactly like what happens in C++, but it's important to know how to do it (and actually do it yourself) in C first, in my opinion. Read the pdf to understand: what inheritance is, and why it's useful.

The pdf also covers virtual functions and how to implement them.

A pure virtual is a function that must be overridden when a class derives from a type. The compiler will complain if you don't. That's all. This is good for enforcing interfaces.

An abstract class is type that is designed to only be used as a base for derivation. Again, a good example (the only good one I know) is for interfaces.

If you're confused on what an interface is: it is just a set of functions to call. If I employ an interface, then other objects can treat me as if I employ this interface. For example say we make an object to resemble a duck. We have an interface for quacking and swimming. Other code portions can call my quack and swim functions upon me, without knowing about the rest of what I am so long as I employ the duck interface. This is actually referred to as "duck-typing".

That's not the definition of duck typing. Duck typing refers to a style of type system that derives its type information from the interface an object exposes rather than from a inheritance tree that was explicitly laid out. It is common in dynamic languages (Javascript, Ruby, Python, PHP) but can also exist in statically typed languages (Go uses a form of duck typing, for instance). What you described is simply 'polymorphism'.

Also, I don't think understanding how to implement inheritance in C is at all necessary and most definitely overkill for understanding how inheritance, virtual functions, and abstract classes work. The vast majority of programmers likely have no idea how vtables work (and there are very few times where knowing such information will actually matter). Telling someone who is having their first foray into OO to learn all of that stuff is bordering on sadistic.

Well he said he's learning this for school, and when I went to school I learned all that stuff. I still stand by all I said except the duck typing thing.
phar
Profile Joined August 2011
United States1080 Posts
Last Edited: 2013-03-18 03:37:56
March 18 2013 03:35 GMT
#5423
It is in no way important to know how to do inheritance in C. Just like it's not important to know how a CPU works. It can be fun to learn for those of us who are sadistic, but it's not important or useful. Encouraging learning is good, but you gotta be realistic about it.

If every programmer was made to go through the physics of transistors, low level processor and memory architecture, assembly, all the way up... we'd have a lot less programmers. You could argue that the ones remaining would be better somehow (debatable), but we need way more programmers than we have already. Unless you have a solution to the H1-B deficiency problem :\
Who after all is today speaking about the destruction of the Armenians?
AmericanUmlaut
Profile Blog Joined November 2010
Germany2581 Posts
March 18 2013 07:16 GMT
#5424
I agree. Every programmer should learn to write a bit of assembly and have at least a basic idea of how transistor logic works, and maybe even learn how to write OO code in C. That's not where you point a beginner, though. A beginner should start somewhere in the middle, learning to write basic programs a high-level programming language, and then work their way down into low-level stuff and up into the world of operating system APIs and network code and threading. Teaching someone OO by making them do it in C is dumping too much complexity on their heads all at once, it's much better to let them learn the concept (which is complicated enough if you're new to it) and then later learn how the concept is actually implemented at a low level.

Also, CecilSunkure, you wrote that the only case you know for an abstract class is in writing an interface. There's a subtle difference between the two concepts, though. An interface is just a communication contract - implementing an interface is basically promising to present a defined set of public methods. An abstract class is a class that isn't intended to be instantiated, but only to be inherited from. The difference is that an interface doesn't provide implementation, but an abstract class can. I have an abstract class in a project I'm working on right now called Link, for example, which represents a link, which can be of type internal, external or download. The base Link class implements a render() method and defines the abstract getUrl() method, which is implemented by each of the three derived classes. If Link were an interface rather than an abstract class, all of the classes implementing it would have to have their own implementation of render().
The frumious Bandersnatch
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
March 18 2013 08:14 GMT
#5425
On March 18 2013 16:16 AmericanUmlaut wrote:
I agree. Every programmer should learn to write a bit of assembly and have at least a basic idea of how transistor logic works, and maybe even learn how to write OO code in C. That's not where you point a beginner, though. A beginner should start somewhere in the middle, learning to write basic programs a high-level programming language, and then work their way down into low-level stuff and up into the world of operating system APIs and network code and threading. Teaching someone OO by making them do it in C is dumping too much complexity on their heads all at once, it's much better to let them learn the concept (which is complicated enough if you're new to it) and then later learn how the concept is actually implemented at a low level.

Also, CecilSunkure, you wrote that the only case you know for an abstract class is in writing an interface. There's a subtle difference between the two concepts, though. An interface is just a communication contract - implementing an interface is basically promising to present a defined set of public methods. An abstract class is a class that isn't intended to be instantiated, but only to be inherited from. The difference is that an interface doesn't provide implementation, but an abstract class can. I have an abstract class in a project I'm working on right now called Link, for example, which represents a link, which can be of type internal, external or download. The base Link class implements a render() method and defines the abstract getUrl() method, which is implemented by each of the three derived classes. If Link were an interface rather than an abstract class, all of the classes implementing it would have to have their own implementation of render().

Well I'm not here to argue, though I myself learned C, then learned OO in C, then moved to C++. It's in my opinion that others would do wise to do the same and that's why I recommend it.

And thanks for the clarification on abstract classes! I believe the reason I didn't make a clear distinction is because I use template mixins to avoid run-time costs of polymorphism. So I don't really think of CRTP mixins as "abstract classes" since I don't have the = 0 pure specifier
nunez
Profile Blog Joined February 2011
Norway4003 Posts
March 18 2013 09:46 GMT
#5426
On March 18 2013 17:14 CecilSunkure wrote:
Show nested quote +
On March 18 2013 16:16 AmericanUmlaut wrote:
I agree. Every programmer should learn to write a bit of assembly and have at least a basic idea of how transistor logic works, and maybe even learn how to write OO code in C. That's not where you point a beginner, though. A beginner should start somewhere in the middle, learning to write basic programs a high-level programming language, and then work their way down into low-level stuff and up into the world of operating system APIs and network code and threading. Teaching someone OO by making them do it in C is dumping too much complexity on their heads all at once, it's much better to let them learn the concept (which is complicated enough if you're new to it) and then later learn how the concept is actually implemented at a low level.

Also, CecilSunkure, you wrote that the only case you know for an abstract class is in writing an interface. There's a subtle difference between the two concepts, though. An interface is just a communication contract - implementing an interface is basically promising to present a defined set of public methods. An abstract class is a class that isn't intended to be instantiated, but only to be inherited from. The difference is that an interface doesn't provide implementation, but an abstract class can. I have an abstract class in a project I'm working on right now called Link, for example, which represents a link, which can be of type internal, external or download. The base Link class implements a render() method and defines the abstract getUrl() method, which is implemented by each of the three derived classes. If Link were an interface rather than an abstract class, all of the classes implementing it would have to have their own implementation of render().

Well I'm not here to argue, though I myself learned C, then learned OO in C, then moved to C++. It's in my opinion that others would do wise to do the same and that's why I recommend it.

And thanks for the clarification on abstract classes! I believe the reason I didn't make a clear distinction is because I use template mixins to avoid run-time costs of polymorphism. So I don't really think of CRTP mixins as "abstract classes" since I don't have the = 0 pure specifier


CRTP is f.ex used for static polymorphism. the base class would be your abstract class providing an interface, the functions in which it calls derived member functions would be like pure virtual functions. you can very much so think of the CRTP base class as an abstract class.

i don't think (pure) virtual functions and abstract class even makes sense besides as analogues in a CRTP context.
conspired against by a confederacy of dunces.
mcc
Profile Joined October 2010
Czech Republic4646 Posts
March 18 2013 16:11 GMT
#5427
On March 16 2013 12:33 tec27 wrote:
Show nested quote +
On March 16 2013 01:46 mcc wrote:
On March 16 2013 00:04 AmericanUmlaut wrote:
Types in JS are a bloody nightmare.

typeof(NaN) => "Number"

Yay Javascript.

Yep, JS type design is terrible shit. Empty string is equivalent to false, who knew Caused me some wasted time yesterday.

Empty string does not equal false, it is merely a falsy value. Falsy values are very useful, and greatly increase the expressiveness of the language imo. I've programmed in JS a lot, and I can tell you that if you're actually checking if a variable equals or does not equal a falsy value, you are generally not doing the right thing anyway. But just in case, I'd recommend running your code through http://jshint.com (there's a command-line version as well if you'd like to lint through your editor/console) and it'll catch cases where you compare against falsy values without using !== or ===.

JS has some weird idiosyncracies, but its type system isn't one of them and makes for a very expressive and useful language.

I was checking old code for a bug and it looked ok on the first glance, I found the issue later once I understood what the code was exactly doing. In more strict language I would have found this error in small fraction of a time. Which brings me to a point, "very expressive" is not a good property of a language in 90% of cases as it mostly means it gives you slightly faster coding time, but sacrifices maintainability. So for short programs that need to be quickly done they are ok-ish, for anything else they just complicate bugfixing and extending the program.

To expand on it a bit more I will start by saying that "people should code well" is not a proper argument as there will always be bad code created by bad (or even good) programmers for multitude of reasons. Thus a language that cuts off some part of those bad possibilities by force will more than offset any lack of expressiveness in development that is measured in more than weeks.

To make it short I see absolutely no gain in the JS type system that is not more than offset by issues it causes. I am not saying it does not have some inner sense, but so have many things that are in practice terrible.
heroyi
Profile Blog Joined March 2009
United States1064 Posts
Last Edited: 2013-03-18 16:35:16
March 18 2013 16:30 GMT
#5428
This may seem out of topic but I am curious as to what others think:

I was in a library studying near a bathroom entrance. Two lads ran into each other in the bathroom and started talking. Long story short they were discussing about software engineering/comp sci majors. One of the lad proceeded to discuss how it is a terrible major and it will "fall" and soon become useless. His reasoning was that it was too "easy" to have the jobs outsourced to "India or Pakistan."

This is something that quite a lot of people believe in actually and I am a bit disturbed. I personally think this is a load of horse crap considering how much money different companies (google and microsoft) and countries (Middle east and Europe like UK) are pumping into this field as we speak. Hell, even legislation in the US are discussing about making programming a recommended elective to HS for graduation. With so many signs and pleading by companies asking for more certified programmers I fail to see how this is a failing crap degree (to put it lightly). Maybe he mixed his definition up with offshoring perhaps?

I don't know. Maybe I am delusional but anyone here care to take a jab and strengthen or destroy my belief (and perhaps inspire or discourage others to take this major)?
wat wat in my pants
obesechicken13
Profile Blog Joined July 2008
United States10467 Posts
Last Edited: 2013-03-18 16:38:14
March 18 2013 16:33 GMT
#5429
On March 19 2013 01:30 heroyi wrote:
This may seem out of topic but I am curious as to what others think:

I was in a library studying near a bathroom entrance. Two lads ran into each other in the bathroom and started talking. Long story short they were discussing about software engineering/comp sci majors. One of the lad proceeded to discuss how it is a terrible major and it will "fall" and soon become useless. His reasoning was that it was too "easy" to have the jobs outsourced to "India or Pakistan."

This is something that quite a lot of people believe in actually and I am a bit disturbed. I personally think this is a load of horse crap considering how much money different companies (google and microsoft) and countries (Middle east and Europe like UK) are being pumped into this field as we speak. Hell, even legislation in the US are discussing about making programming a core class(elective) to graduate. With so many signs and pleading by companies asking for more certified programmers I fail to see how this is a failing crap degree (to put it lightly).

I don't know. Maybe I am delusional but anyone here care to take a jab and strengthen or destroy my belief (and perhaps inspire or discourage others to take this major)?

I think my company is trying to outsource our old products to India but keep our new ones in shore. It's kinda dumb since the people in India are so smart, but it's a very nice deal for us if this works. I think the reasoning is that the communication is better.

That said, no one knows what the future holds. People are bad at predicting things, like the recession. You sometimes have to take the risk.

Universities try to teach you things that can't be outsourced like really specialized energy systems, robotics, communications, electrical jobs.
I think in our modern age technology has evolved to become more addictive. The things that don't give us pleasure aren't used as much. Work was never meant to be fun, but doing it makes us happier in the long run.
heroyi
Profile Blog Joined March 2009
United States1064 Posts
Last Edited: 2013-03-18 16:38:18
March 18 2013 16:37 GMT
#5430
On March 19 2013 01:33 obesechicken13 wrote:
Show nested quote +
On March 19 2013 01:30 heroyi wrote:
This may seem out of topic but I am curious as to what others think:

I was in a library studying near a bathroom entrance. Two lads ran into each other in the bathroom and started talking. Long story short they were discussing about software engineering/comp sci majors. One of the lad proceeded to discuss how it is a terrible major and it will "fall" and soon become useless. His reasoning was that it was too "easy" to have the jobs outsourced to "India or Pakistan."

This is something that quite a lot of people believe in actually and I am a bit disturbed. I personally think this is a load of horse crap considering how much money different companies (google and microsoft) and countries (Middle east and Europe like UK) are being pumped into this field as we speak. Hell, even legislation in the US are discussing about making programming a core class(elective) to graduate. With so many signs and pleading by companies asking for more certified programmers I fail to see how this is a failing crap degree (to put it lightly).

I don't know. Maybe I am delusional but anyone here care to take a jab and strengthen or destroy my belief (and perhaps inspire or discourage others to take this major)?

I think my company is trying to outsource our old products to India but keep our new ones in shore. It's kinda dumb since the people in India are so smart, but it's a very nice deal for us if this works. I think the reasoning is that the communication is better.

But you are outsourcing the old products while keeping new in. That isn't new at all to the business model.

The guys argument comes in that the outsourced country can pump out softwares out quickly and as many as possible while being cheap. However, he doesn't take into the account the quality of a coding and we all know how costly bugged codes can be.
wat wat in my pants
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2013-03-18 17:22:51
March 18 2013 17:22 GMT
#5431
On March 18 2013 17:14 CecilSunkure wrote:
Show nested quote +
On March 18 2013 16:16 AmericanUmlaut wrote:
I agree. Every programmer should learn to write a bit of assembly and have at least a basic idea of how transistor logic works, and maybe even learn how to write OO code in C. That's not where you point a beginner, though. A beginner should start somewhere in the middle, learning to write basic programs a high-level programming language, and then work their way down into low-level stuff and up into the world of operating system APIs and network code and threading. Teaching someone OO by making them do it in C is dumping too much complexity on their heads all at once, it's much better to let them learn the concept (which is complicated enough if you're new to it) and then later learn how the concept is actually implemented at a low level.

Also, CecilSunkure, you wrote that the only case you know for an abstract class is in writing an interface. There's a subtle difference between the two concepts, though. An interface is just a communication contract - implementing an interface is basically promising to present a defined set of public methods. An abstract class is a class that isn't intended to be instantiated, but only to be inherited from. The difference is that an interface doesn't provide implementation, but an abstract class can. I have an abstract class in a project I'm working on right now called Link, for example, which represents a link, which can be of type internal, external or download. The base Link class implements a render() method and defines the abstract getUrl() method, which is implemented by each of the three derived classes. If Link were an interface rather than an abstract class, all of the classes implementing it would have to have their own implementation of render().

Well I'm not here to argue, though I myself learned C, then learned OO in C, then moved to C++. It's in my opinion that others would do wise to do the same and that's why I recommend it.

And thanks for the clarification on abstract classes! I believe the reason I didn't make a clear distinction is because I use template mixins to avoid run-time costs of polymorphism. So I don't really think of CRTP mixins as "abstract classes" since I don't have the = 0 pure specifier



How do you learn OO in C? C isn't an object-oriented language unless you mean C++/Objective C here.
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
Last Edited: 2013-03-18 18:11:09
March 18 2013 17:59 GMT
#5432
On March 19 2013 02:22 darkness wrote:
Show nested quote +
On March 18 2013 17:14 CecilSunkure wrote:
On March 18 2013 16:16 AmericanUmlaut wrote:
I agree. Every programmer should learn to write a bit of assembly and have at least a basic idea of how transistor logic works, and maybe even learn how to write OO code in C. That's not where you point a beginner, though. A beginner should start somewhere in the middle, learning to write basic programs a high-level programming language, and then work their way down into low-level stuff and up into the world of operating system APIs and network code and threading. Teaching someone OO by making them do it in C is dumping too much complexity on their heads all at once, it's much better to let them learn the concept (which is complicated enough if you're new to it) and then later learn how the concept is actually implemented at a low level.

Also, CecilSunkure, you wrote that the only case you know for an abstract class is in writing an interface. There's a subtle difference between the two concepts, though. An interface is just a communication contract - implementing an interface is basically promising to present a defined set of public methods. An abstract class is a class that isn't intended to be instantiated, but only to be inherited from. The difference is that an interface doesn't provide implementation, but an abstract class can. I have an abstract class in a project I'm working on right now called Link, for example, which represents a link, which can be of type internal, external or download. The base Link class implements a render() method and defines the abstract getUrl() method, which is implemented by each of the three derived classes. If Link were an interface rather than an abstract class, all of the classes implementing it would have to have their own implementation of render().

Well I'm not here to argue, though I myself learned C, then learned OO in C, then moved to C++. It's in my opinion that others would do wise to do the same and that's why I recommend it.

And thanks for the clarification on abstract classes! I believe the reason I didn't make a clear distinction is because I use template mixins to avoid run-time costs of polymorphism. So I don't really think of CRTP mixins as "abstract classes" since I don't have the = 0 pure specifier



How do you learn OO in C? C isn't an object-oriented language unless you mean C++/Objective C here.


C has structures, which is analogous to an object in that each copy of the structure can have its own variables, functions, and purpose. It just isn't done for you the way C++/Java do it, you have to manually setup the functions and call them. Its actually very good practice for understanding how higher level languages organize objects in memory, and how garbage collection works.

There isn't inheritance, but it's got polymorphism (weak static types) and encapsulation (structures).

From StackOverflow:

typedef struct {
int (*open)(void *self, char *fspec);
int (*close)(void *self);
int (*read)(void *self, void *buff, size_t max_sz, size_t *p_act_sz);
int (*write)(void *self, void *buff, size_t max_sz, size_t *p_act_sz);
// And data goes here.
} tCommClass;

tCommClass commRs232;
commRs232.open = &rs232Open;
: :
commRs232.write = &rs232Write;

tCommClass commTcp;
commTcp.open = &tcpOpen;
: :
commTcp.write = &tcpWrite;


In a personal note, I see this pattern used very extensively in the operating system I work on. The BSD file system is basically an enormous example of OO practices in C, so this isn't some niche feature of the language.
Any sufficiently advanced technology is indistinguishable from magic
DeltaX
Profile Joined August 2011
United States287 Posts
March 18 2013 18:57 GMT
#5433
On March 19 2013 01:37 heroyi wrote:
Show nested quote +
On March 19 2013 01:33 obesechicken13 wrote:
On March 19 2013 01:30 heroyi wrote:
This may seem out of topic but I am curious as to what others think:

I was in a library studying near a bathroom entrance. Two lads ran into each other in the bathroom and started talking. Long story short they were discussing about software engineering/comp sci majors. One of the lad proceeded to discuss how it is a terrible major and it will "fall" and soon become useless. His reasoning was that it was too "easy" to have the jobs outsourced to "India or Pakistan."

This is something that quite a lot of people believe in actually and I am a bit disturbed. I personally think this is a load of horse crap considering how much money different companies (google and microsoft) and countries (Middle east and Europe like UK) are being pumped into this field as we speak. Hell, even legislation in the US are discussing about making programming a core class(elective) to graduate. With so many signs and pleading by companies asking for more certified programmers I fail to see how this is a failing crap degree (to put it lightly).

I don't know. Maybe I am delusional but anyone here care to take a jab and strengthen or destroy my belief (and perhaps inspire or discourage others to take this major)?

I think my company is trying to outsource our old products to India but keep our new ones in shore. It's kinda dumb since the people in India are so smart, but it's a very nice deal for us if this works. I think the reasoning is that the communication is better.

But you are outsourcing the old products while keeping new in. That isn't new at all to the business model.

The guys argument comes in that the outsourced country can pump out softwares out quickly and as many as possible while being cheap. However, he doesn't take into the account the quality of a coding and we all know how costly bugged codes can be.


It also does not take into account that there are risks in outsourcing. A retailer who wants to make a website does not really risk much by outsourcing it as the software is not really a core part of their business, but if the software IS the business, then it could be much harder to keep critical parts of it secret. In manufacturing there are cases where the people who run a factory in china take what they learned and start competing with the original company.

There will also always be critical systems that require US citizens to fill for people like government/defense contractors.
Frigo
Profile Joined August 2009
Hungary1023 Posts
March 18 2013 19:49 GMT
#5434
On March 19 2013 02:59 RoyGBiv_13 wrote:
C has structures, which is analogous to an object in that each copy of the structure can have its own variables, functions, and purpose. It just isn't done for you the way C++/Java do it, you have to manually setup the functions and call them. Its actually very good practice for understanding how higher level languages organize objects in memory, and how garbage collection works.

There isn't inheritance, but it's got polymorphism (weak static types) and encapsulation (structures).

From StackOverflow:

typedef struct {
int (*open)(void *self, char *fspec);
int (*close)(void *self);
int (*read)(void *self, void *buff, size_t max_sz, size_t *p_act_sz);
int (*write)(void *self, void *buff, size_t max_sz, size_t *p_act_sz);
// And data goes here.
} tCommClass;

tCommClass commRs232;
commRs232.open = &rs232Open;
: :
commRs232.write = &rs232Write;

tCommClass commTcp;
commTcp.open = &tcpOpen;
: :
commTcp.write = &tcpWrite;


In a personal note, I see this pattern used very extensively in the operating system I work on. The BSD file system is basically an enormous example of OO practices in C, so this isn't some niche feature of the language.


I can not decide whether that is brilliantly beautiful or sickeningly disgusting.

It is certainly a clever hack, but it simply can not compete with languages natively supporting inheritance, polymorphism and multiple levels of encapsulation. Lack of "automated" features simply cut into your useful development time.
http://www.fimfiction.net/user/Treasure_Chest
Ilintar
Profile Joined October 2002
Poland794 Posts
March 18 2013 20:26 GMT
#5435
Agreed - coding OOP in C is like coding lambda abstractions in Java - might be fun or useful as an exercise, but in both cases there are simply languages better suited for the job.
Former webmaster @ WGTour.com / BWLauncher developer
windzor
Profile Joined October 2010
Denmark1013 Posts
March 18 2013 20:26 GMT
#5436
On March 19 2013 04:49 Frigo wrote:
Show nested quote +
On March 19 2013 02:59 RoyGBiv_13 wrote:
C has structures, which is analogous to an object in that each copy of the structure can have its own variables, functions, and purpose. It just isn't done for you the way C++/Java do it, you have to manually setup the functions and call them. Its actually very good practice for understanding how higher level languages organize objects in memory, and how garbage collection works.

There isn't inheritance, but it's got polymorphism (weak static types) and encapsulation (structures).

From StackOverflow:

typedef struct {
int (*open)(void *self, char *fspec);
int (*close)(void *self);
int (*read)(void *self, void *buff, size_t max_sz, size_t *p_act_sz);
int (*write)(void *self, void *buff, size_t max_sz, size_t *p_act_sz);
// And data goes here.
} tCommClass;

tCommClass commRs232;
commRs232.open = &rs232Open;
: :
commRs232.write = &rs232Write;

tCommClass commTcp;
commTcp.open = &tcpOpen;
: :
commTcp.write = &tcpWrite;


In a personal note, I see this pattern used very extensively in the operating system I work on. The BSD file system is basically an enormous example of OO practices in C, so this isn't some niche feature of the language.


I can not decide whether that is brilliantly beautiful or sickeningly disgusting.

It is certainly a clever hack, but it simply can not compete with languages natively supporting inheritance, polymorphism and multiple levels of encapsulation. Lack of "automated" features simply cut into your useful development time.


But what you gain in development time you loose in performance. Not every system can use C# or Java but C is in the house and you might want to use OO then. Or you are in an environment where C is the only programming language which can do the stuff you want (operating systems a prime example of this) where if you dont use such schemes you will die a horrible death of code complexity.

Also the described method for OO in C is more or less how C++ classes are implemented, just that instead of fields holding the refererences to functions there is a vtable holding the references to the virtual methods.
Yeah
windzor
Profile Joined October 2010
Denmark1013 Posts
March 18 2013 20:29 GMT
#5437
On March 19 2013 05:26 Ilintar wrote:
Agreed - coding OOP in C is like coding lambda abstractions in Java - might be fun or useful as an exercise, but in both cases there are simply languages better suited for the job.


No some times C is the right language for the job and if the job requeres it OO in C is a useful and important programming scheme to know. The method is highly used in operating systems. The whole driver model in Linux uses it, and it is really easy straitforward to use and program to.
Yeah
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
Last Edited: 2013-03-18 20:42:32
March 18 2013 20:36 GMT
#5438
On March 19 2013 05:26 Ilintar wrote:
Agreed - coding OOP in C is like coding lambda abstractions in Java - might be fun or useful as an exercise, but in both cases there are simply languages better suited for the job.

OOP in C was actually the language of choice for a lot of GBA games. But again the point isn't to learn it professionally, but just to have a solid understanding of how what you're using in C++ works. Using function pointers and typecasting in C for OOP isn't as difficult or tedious as you guys seem to think it is.

On a different topic, if I could I'd code everything in C instead of C++. I really like C. It's just that templating in C++ is so useful, and there are some very nice C++11 features coming around. Whenever someone codes something in C it's almost always completely obvious as to what they are trying to do. With C++ though there are a lot of ways to hide a lot of things. Auto-generated code, things can be run in non-intuitive ways. It's a big problem when a poor C++ programmer is writing code within a team. Of course the solution isn't "lets all code in C", it's just to use C++ appropriately. Even at my school though it's hard to find solid programmers to work with. I can't imagine how hard it would be to find a fit for a team that works primarily with C++ out in the world. Perhaps if more people started "hitting the ground running" in C things would be different?
MiyaviTeddy
Profile Blog Joined October 2008
Canada697 Posts
March 18 2013 22:15 GMT
#5439
Hi guys!


#include <iostream>
using namespace std;

struct A {
virtual void f() { cout << "Class A" << endl; }
};

struct B: A {
void f(int) { cout << "Class B" << endl; }
};

struct C: B {
void f() { cout << "Class C" << endl; }
};

int main() {
B b; C c;
A* pa1 = &b;
A* pa2 = &c;
// b.f();
pa1->f();
pa2->f();
}



So I'm looking through the example and I need some clarification.

I think I get what is going on with


B b; C c;


But after that, I have no idea what is going at that point.
Aiyeeeee
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
Last Edited: 2013-03-18 22:21:38
March 18 2013 22:21 GMT
#5440
On March 19 2013 07:15 MiyaviTeddy wrote:
... snip ...

You should look up inheritance and polymorphism, along with pointers and typecasting.

If you know these then you can see A is treated as a base for other derived cases. The derived cases override a base function being called from A base pointers.
Prev 1 270 271 272 273 274 1032 Next
Please log in or register to reply.
Live Events Refresh
OSC
16:00
OSC Elite Rising Star #17
Nicoract vs MixuLIVE!
Babymarine vs MindelVK
ForJumy vs TBD
Shameless vs Percival
SteadfastSC132
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 664
Lowko470
SteadfastSC 132
ProTech126
MindelVK 34
Codebar 28
StarCraft: Brood War
Britney 21637
Calm 3107
Shuttle 735
GuemChi 550
EffOrt 503
Larva 314
Rush 210
firebathero 159
BeSt 132
Dewaltoss 95
[ Show more ]
PianO 67
yabsab 27
Aegong 19
soO 18
Sacsri 17
scan(afreeca) 12
SilentControl 10
Terrorterran 10
HiyA 10
NaDa 6
JulyZerg 6
Dota 2
Gorgc6718
Dendi949
420jenkins334
XcaliburYe175
Counter-Strike
fl0m4235
zeus304
chrisJcsgo40
minikerr13
Heroes of the Storm
Khaldor148
Other Games
Grubby3580
ArmadaUGS105
Livibee92
Mew2King80
QueenE51
KnowMe50
Trikslyr49
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• poizon28 19
• Reevou 8
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• FirePhoenix0
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 2653
• WagamamaTV579
Other Games
• Shiphtur129
Upcoming Events
Replay Cast
6h 29m
Korean StarCraft League
1d 9h
CranKy Ducklings
1d 16h
WardiTV 2025
1d 18h
SC Evo League
1d 18h
BSL 21
2 days
Sziky vs OyAji
Gypsy vs eOnzErG
OSC
2 days
Solar vs Creator
ByuN vs Gerald
Percival vs Babymarine
Moja vs Krystianer
EnDerr vs ForJumy
sebesdes vs Nicoract
Sparkling Tuna Cup
2 days
WardiTV 2025
2 days
OSC
2 days
[ Show More ]
BSL 21
3 days
Bonyth vs StRyKeR
Tarson vs Dandy
Replay Cast
3 days
Wardi Open
3 days
StarCraft2.fi
3 days
Monday Night Weeklies
3 days
Replay Cast
4 days
WardiTV 2025
4 days
StarCraft2.fi
4 days
PiGosaur Monday
5 days
StarCraft2.fi
5 days
Tenacious Turtle Tussle
6 days
The PondCast
6 days
WardiTV 2025
6 days
StarCraft2.fi
6 days
Liquipedia Results

Completed

Proleague 2025-11-30
RSL Revival: Season 3
Light HT

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
CSCL: Masked Kings S3
Slon Tour Season 2
Acropolis #4 - TS3
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
Kuram Kup
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
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.