• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 02:59
CEST 08:59
KST 15:59
  • 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
[ASL22] Ro8 Preview: In A Tizzy9[ASL22] Ro16 Preview: Holy Diver5[ASL22] Ro16 Preview: Rough Waters10[ASL22] Ro24 Preview: Siren's Call8[ASL22] Ro24 Preview: Summer's End9
Community News
Weekly Cups (Sep 13-20): herO scores triple1BSL Season 235Weekly Cups (Sep 7-12): SHIN, ByuN, MaxPax double down1StarCraft open world shooter announced at BlizzCon101Weekly Cups (Aug 30-Sep 7): herO thrives amid growing schism10
StarCraft 2
General
Balance hotfix patch 5.0.16b (July 16) Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool How do you feel about the StarCraft shooter announcement at BlizzCon 2026? The Death of Cheese: From a Professional Cheeser Weekly Cups (Sep 13-20): herO scores triple
Tourneys
Stellar Fest TWO the Moon (Dec 16-20) Sparkling Tuna Cup - Weekly Open Tournament 2026 GSTL Announcement RSL Revival: Season 6 - Qualifiers and Main Event RSL goes to London! 2026 Offline Finals Nov 21-22
Strategy
[H] ZvP Mid-Late Game: Stalkers Collossi HT
Custom Maps
Nexus Wars 2021 GUIDE [M] (2) Industrial Park
External Content
Mutation # 544 Double Trouble The PondCast: SC2 News & Results Mutation # 543 Enhanced Defenses Mutation # 542 The Ascended
Brood War
General
screpdb: new Starcraft reporting tool an AI researcher's take on the ladder bot BW General Discussion Bot on ladder [ASL22] Ro8 Preview: In A Tizzy
Tourneys
[ASL22] Ro8 Day 2 [ASL22] Ro16 Group D [ASL22] Ro8 Day 1 [IPSL] IPSL is Back With Winter 26-27!
Strategy
Cliff Jump Revisited (1 in a 1000 strategy) Replay Review Process - What do you do? Simple Questions, Simple Answers Odyssey Mineral Stack Saturation
Other Games
General Games
Diablo IV Nintendo Switch Thread Warcraft III: The Frozen Throne Stormgate/Frost Giant Megathread EVE Corporation
Dota 2
Dota 2 Champions League Season 3 Begins April 25! Official 'what is Dota anymore' discussion
League of Legends
[TL LoL EUW IHs] Teemo shall perish
Heroes of the Storm
Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Community Thread
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Artificial Intelligence Thread Things Aren’t Peaceful in Palestine All you football fans (soccer)!
Fan Clubs
MarineLorD Fan Club The Creator Fan Club The ShoWTimE Fan Club
Media & Entertainment
Movie Discussion! [Manga] One Piece Diablo Animated Series on Netflix
Sports
Football (Soccer) Thread TeamLiquid Health and Fitness Initiative For 2023 MLB/Baseball 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Recent Gifted Posts
Blogs
Gaming Intensity, Problemati…
TrAiDoS
38 yo Retired SWE loo…
PurE)Rabbit-SF
Can Bots Beat Pros?? Starcr…
namkraft
[meme] I finally understa…
LUCKY_NOOB
Regacy Esports:Our Goa…
regacyesports
Dreaming of BW patches (mod…
c3rberUs
Customize Sidebar...

Website Feedback

Closed Threads



Active: 7656 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 States3715 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
Germany2597 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 4h 1m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
ProTech105
StarCraft: Brood War
Britney 2324
Rain 1631
GuemChi 583
Zeus 313
Leta 158
Dewaltoss 121
ggaemo 39
ajuk12(nOOB) 18
yabsab 18
Icarus 7
League of Legends
JimRising 688
Reynor101
Super Smash Bros
Mew2King138
Other Games
summit1g10129
ceh9366
PiGStarcraft329
Livibee169
Maynarde131
Happy107
Organizations
Dota 2
PGL Dota 2 - Main Stream2599
Other Games
gamesdonequick484
StarCraft: Brood War
Afreeca ASL 278
[ Show 12 non-featured ]
StarCraft 2
• mYiSmile112
• Letter145
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• Migwel
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• lizZardDota2165
League of Legends
• Stunt560
Upcoming Events
Kung Fu Cup
4h 1m
The PondCast
1d 3h
Replay Cast
1d 17h
Korean StarCraft League
2 days
CranKy Ducklings
3 days
GSL
4 days
Yamato Cup
4 days
Replay Cast
4 days
Afreeca Starleague
5 days
WardiTV Weekly
5 days
[ Show More ]
Sparkling Tuna Cup
6 days
Afreeca Starleague
6 days
PiGosaur Cup
6 days
Liquipedia Results

Completed

Super Anchor Qualifying S3
Blizzard Classic Cup 2026
Big Dog Cup 2026 Div 1

Ongoing

ASL Season 22
CSL 2026 AUTUMN (S22)
Acropolis #5
Acropolis #5 - GSA
Calamity Invitational
Logitech G Play Connect 2026
SL StarSeries Fall 2026
FISSURE Playground #3
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
Stake Ranked Episode 3
XSE Pro League 2026

Upcoming

Acropolis #5 - GSB
Acropolis #5 - GSC
BSL Season 23
SC4ALL II: Brood War
BSL 23: Non-Korean Championship
HSC XXX
Stellar Fest 2: Lunar Cup
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
RSL Offline Finals
Custodian Cup
Copium Cup
PGL Major Singapore 2026
Stake Ranked Episode 6
BLAST Rivals Fall 2026
IEM Beijing 2026
Stake Ranked Episode 5
PGL Masters Bucharest 2026
1win Private Club #2
Thunderpick World Champ. '26
ESL Pro League Season 24
Stake Ranked Episode 4
1win Private Club #1
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.