• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 00:12
CET 05:12
KST 13:12
  • 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
ByuL: The Forgotten Master of ZvT30Behind the Blue - Team Liquid History Book19Clem wins HomeStory Cup 289HomeStory Cup 28 - Info & Preview13Rongyi Cup S3 - Preview & Info8
Community News
2026 KongFu Cup Announcement4BGE Stara Zagora 2026 cancelled12Blizzard Classic Cup - Tastosis announced as captains15Weekly Cups (March 2-8): ByuN overcomes PvT block4GSL CK - New online series19
StarCraft 2
General
GSL CK - New online series BGE Stara Zagora 2026 cancelled Blizzard Classic Cup - Tastosis announced as captains BGE Stara Zagora 2026 announced ByuL: The Forgotten Master of ZvT
Tourneys
2026 KongFu Cup Announcement RSL Season 4 announced for March-April PIG STY FESTIVAL 7.0! (19 Feb - 1 Mar) Sparkling Tuna Cup - Weekly Open Tournament [GSL CK] Team Maru vs. Team herO
Strategy
Custom Maps
Publishing has been re-enabled! [Feb 24th 2026] Map Editor closed ?
External Content
Mutation # 517 Distant Threat The PondCast: SC2 News & Results Mutation # 516 Specter of Death Mutation # 515 Together Forever
Brood War
General
ASL21 General Discussion BSL 22 Map Contest — Submissions OPEN to March 10 BGH Auto Balance -> http://bghmmr.eu/ Are you ready for ASL 21? Hype VIDEO Gypsy to Korea
Tourneys
[Megathread] Daily Proleagues [BSL22] Open Qualifiers & Ladder Tours IPSL Spring 2026 is here! ASL Season 21 Qualifiers March 7-8
Strategy
Simple Questions, Simple Answers Soma's 9 hatch build from ASL Game 2 Fighting Spirit mining rates Zealot bombing is no longer popular?
Other Games
General Games
Path of Exile Stormgate/Frost Giant Megathread Nintendo Switch Thread PC Games Sales Thread No Man's Sky (PS4 and PC)
Dota 2
Official 'what is Dota anymore' discussion The Story of Wings Gaming
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
Five o'clock TL Mafia Mafia Game Mode Feedback/Ideas Vanilla Mini Mafia TL Mafia Community Thread
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Mexico's Drug War Russo-Ukrainian War Thread NASA and the Private Sector
Fan Clubs
The IdrA Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! [Req][Books] Good Fantasy/SciFi books
Sports
Formula 1 Discussion 2024 - 2026 Football Thread General nutrition recommendations Cricket [SPORT] TL MMA Pick'em Pool 2013
World Cup 2022
Tech Support
Laptop capable of using Photoshop Lightroom?
TL Community
The Automated Ban List
Blogs
Funny Nicknames
LUCKY_NOOB
Money Laundering In Video Ga…
TrAiDoS
Iranian anarchists: organize…
XenOsky
FS++
Kraekkling
Shocked by a laser…
Spydermine0240
Unintentional protectionism…
Uldridge
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2403 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
Germany2594 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
Next event in 3h 48m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RuFF_SC2 289
ProTech129
StarCraft: Brood War
GuemChi 4299
ggaemo 87
Leta 83
ZergMaN 38
Noble 38
Icarus 9
Dota 2
NeuroSwarm153
LuMiX1
League of Legends
JimRising 677
Counter-Strike
taco 924
Stewie2K7
Super Smash Bros
hungrybox452
Heroes of the Storm
Khaldor151
Other Games
summit1g11868
C9.Mang0309
Maynarde150
Organizations
Other Games
gamesdonequick843
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• practicex 78
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Lourlo1310
• Rush1188
• Stunt318
Upcoming Events
GSL
3h 48m
Wardi Open
7h 48m
Monday Night Weeklies
12h 48m
WardiTV Team League
1d 7h
PiGosaur Cup
1d 19h
Kung Fu Cup
2 days
OSC
2 days
The PondCast
3 days
KCM Race Survival
3 days
WardiTV Team League
3 days
[ Show More ]
Replay Cast
3 days
KCM Race Survival
4 days
WardiTV Team League
4 days
Korean StarCraft League
4 days
uThermal 2v2 Circuit
5 days
BSL
5 days
BSL
6 days
Replay Cast
6 days
Liquipedia Results

Completed

Proleague 2026-03-13
WardiTV Winter 2026
Underdog Cup #3

Ongoing

KCM Race Survival 2026 Season 1
Jeongseon Sooper Cup
BSL Season 22
CSL Elite League 2026
RSL Revival: Season 4
Nations Cup 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual

Upcoming

ASL Season 21
Acropolis #4 - TS6
2026 Changsha Offline CUP
Acropolis #4
IPSL Spring 2026
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
NationLESS Cup
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 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.