What is a model?

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

GTM
Posts: 90
Joined: Tue Nov 10, 2009 4:53 am UTC

What is a model?

Postby GTM » Tue Jul 23, 2013 4:52 pm UTC

This is most definitely a very basic concept that I cannot grasp.

Was talking to a prof, and couldn't grasp what he meant by a model. He said something along the lines "When features are added to a model, it has to fit in the model." I'm confused. If it doesn't fit, wouldn't you add it to make it fit? Say when the C language model was being designed, and they didn't have loops yet. The way loops are implemented I assume "fits", but if loops didn't 'fit', wouldn't you just add it, say, by adding a loop keyword or something, to just make it fit?

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: What is a model?

Postby korona » Tue Jul 23, 2013 7:40 pm UTC

A model can mean various things depending on the context. In formal logic "model" has a certain mathematical meaning.

In other contexts "model" usually means "abstraction" or "idealization". For example it could mean abstraction from reality.

If you could give us more details about the context that term was used in we could give you a more precise answer.

GTM
Posts: 90
Joined: Tue Nov 10, 2009 4:53 am UTC

Re: What is a model?

Postby GTM » Tue Jul 23, 2013 10:13 pm UTC

Well, it's similar to the example I have about on the C language. I'm designing a language, and we have a "model", which to me, looks like a bunch of keywords which can create a certain subset of program types. We're deciding on new features to add, and he keeps saying how some implementations may not fit the model, which doesn't really make sense to me, as if it doesn't fit, I assume we can add a keyword or something to allow it to fit.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: What is a model?

Postby EvanED » Tue Jul 23, 2013 10:26 pm UTC

Think of "model" in that usage to be somewhat like "how well does it fit with the other features and your goals for the language."

An extreme example would be something like adding assignment operators to a pure functional language like Haskell or Clojure.1 Don't worry if you don't know what this means; basically there are languages out there that are based around ideas other than changing the values of variables a bunch. The point is that adding assignment to those languages would be a complete violation of how the language was designed, because sort of the whole point of those languages is that variables can't be changed.

There are also places where two language features can interact poorly or surprisingly. (Those two adjectives are closer than you may think right now. :-)) It may be that either one is fine on its own, but when you put them together, there may be something like emergent behavior that makes predicting what happens difficult. C++ probably has some zingers like this, but I'm actually blanking right now and can't think of a good example.

Finally, it may just be that a new feature doesn't fit into a language very well because it's basically unneeded. For instance, it would be possible to add a loop_forever { .... } construct to C. (Obviously using one productively would require a break somewhere inside of it or something like that, but such a thing really would get used if it were there.) But... there's not really a reason to do that. C already has two reasonable ways of writing loop_forever: for(;;) and while(true).

1 Yes, there are limited notions of assignment in both. Shut up. :-) (Not you, GTM)

elasto
Posts: 3757
Joined: Mon May 10, 2010 1:53 am UTC

Re: What is a model?

Postby elasto » Wed Jul 24, 2013 1:11 pm UTC

Yeah. Think of programming languages as like tools in a toolbox. One language might be like a hammer, another like a hacksaw and yet another like a screwdriver.

You might think it'd be a good idea to have an 'omni-language' that can do anything and everything, but in reality it makes about as much sense as trying to have an 'omni-tool' that can be a hammer or a hacksaw or a screwdriver. It'd be hideous and ugly, complicated and confusing - perhaps even dangerous to use, and ultimately would do a poorer job in every department than just keeping a nice, clean division into simple, specialised tools each with a clearly defined role.

When your professor says 'that doesn't fit the model', it means you're taking your elegant, precision screwdriver and bolting on something huge and ugly to make it also double as a hammer :D

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: What is a model?

Postby You, sir, name? » Wed Jul 24, 2013 6:29 pm UTC

elasto wrote:When your professor says 'that doesn't fit the model', it means you're taking your elegant, precision screwdriver and bolting on something huge and ugly to make it also double as a hammer :D


Duct tape a plastic hammer head, a rusty saw blade, a baseball mitt, and an empty soda bottle to it, and you get PHP.

zing
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
Link
Posts: 1407
Joined: Sat Mar 07, 2009 11:33 am UTC
Location: ᘝᓄᘈᖉᐣ
Contact:

Re: What is a model?

Postby Link » Thu Jul 25, 2013 4:25 pm UTC

EvanED wrote:For instance, it would be possible to add a loop_forever { .... } construct to C. (Obviously using one productively would require a break somewhere inside of it or something like that, but such a thing really would get used if it were there.)

Nitpick: you don't always need a break to use an infinite loop productively. In embedded programming, for instance, you usually have an infinite main loop, and breaking out of it is generally considered a Very Bad Thing™ (unless there's some reset code immediately after it, anyway -- it's returning from the main function that leaves you with a Really Big Problem®).

You, sir, name? wrote:Duct tape a plastic hammer head, a rusty saw blade, a baseball mitt, and an empty soda bottle to it, and you get PHP.
:lol:

wumpus
Posts: 546
Joined: Thu Feb 21, 2008 12:16 am UTC

Re: What is a model?

Postby wumpus » Thu Jul 25, 2013 6:48 pm UTC

You, sir, name? wrote:
elasto wrote:When your professor says 'that doesn't fit the model', it means you're taking your elegant, precision screwdriver and bolting on something huge and ugly to make it also double as a hammer :D


Duct tape a plastic hammer head, a rusty saw blade, a baseball mitt, and an empty soda bottle to it, and you get PHP.

zing


Is this pretty common? Some thoughts:
My personal experience is with Python. Python 2.x seemed to be entirely designed within the model, and flow from python 1.x. Python 3 seemed to try to graft unicode where exact strings had been, leaving a mess of junk between "unicode strings (no encoding)", "unicode strings (encoded)", and "bytes". None of these seemed to do *any* of the functions I used strings for except for unicode use (which even though it covered *all* human readable strings, was still a sufficiently special case that python 2.x handled it just fine).

C++ seems a language that doesn't have a model. It has an encyclopedia of hacks. The only thing it has going for it is compatibility with C, which it likely only gained by forcing itself to use the C model, and then hacking itself it until it got that way.

Objective C, D, that other D, another D, some other object oriented C, all likely didn't succeed compared to C++ since they used their own OO model, and thus sacrificed C compatibility.

BASIC seems to be the exception that proves the rule. Going from MS-BASIC (and similar 8 bit BASICs) to quickBasic to Visiual Basic to VB seems an exersize in gaining elegance. Largely this is due to just how awful BASIC was and that simply apeing more elegant languages was a good fix.

I strongly suspect this is why I haven't heard of large scale PERL projects for awhile. I don't think I've heard of anyone doing a "project" in PERL. I'm pretty sure good sysadmins still do their housekeeping in one-off PERL scripts.

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: What is a model?

Postby You, sir, name? » Thu Jul 25, 2013 7:02 pm UTC

Python isn't poorly designed, not like PHP. Python is like a swiss army knife--it can do a lot, but its got a consistent theme. Although some would argue that it's support for functional programming is a mistake or out of place. But that is nothing. PHP plays in a different league altogether. It is notoriously badly designed, in a multitude of ways best explained in the classic essay PHP: A fractal of bad design.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
WanderingLinguist
Posts: 237
Joined: Tue May 22, 2012 5:14 pm UTC
Location: Seoul
Contact:

Re: What is a model?

Postby WanderingLinguist » Thu Jul 25, 2013 9:43 pm UTC

wumpus wrote:Objective C, D, that other D, another D, some other object oriented C, all likely didn't succeed compared to C++ since they used their own OO model, and thus sacrificed C compatibility.


Have you even used Objective-C? It's a strict superset of C, meaning that there are no compatibility sacrifices whatsoever. C programs run just fine under Objective-C without any modification. (The same cannot be said of C++, which did sacrifice compatibility).

User avatar
sparkyb
Posts: 1091
Joined: Thu Sep 06, 2007 7:30 pm UTC
Location: Camberville proper!
Contact:

Re: What is a model?

Postby sparkyb » Thu Jul 25, 2013 9:48 pm UTC

PHP has probably one of the most hodgepodge models, but seems understandable compared to the totally unintuitive mode of Perl. Perl has a very distinct model, but it sucks at being human readable.

No one has mentioned JavaScript. I loath the design/model of JavaScript even more than PHP or Perl. Similarly to Perl, JavaScript does have a definite model, but it's just not one I like. Perl's biggest problem is syntax, but operationally it works like most things. JavaScript's syntax is reasonable, but its prototypical inheritance model is really counter-intuitive. I can't ever remember how it works or how to do anything in that language, and from what I can tell from all the JS code I've read, no one else can agree on the right way to do stuff either. When your language needs an apologist book called "JavaScript: The Good Parts" to teach that the language isn't all bad, so long as you ignore certain bad parts, that's when you know you have problems.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: What is a model?

Postby EvanED » Thu Jul 25, 2013 11:55 pm UTC

sparkyb wrote:I loath the design/model of JavaScript even more than PHP or Perl. ... When your language needs an apologist book called "JavaScript: The Good Parts" to teach that the language isn't all bad, so long as you ignore certain bad parts, that's when you know you have problems.

You know why no one has written "PHP: The Good Parts"?
Spoiler:
There aren't any!

Spoiler:
*rimshot*

Spoiler:
OK that was probably the least surprising punchline and least funny joke ever

Spoiler:
No nested spoilers? That makes me sad.

User avatar
Xenomortis
Not actually a special flower.
Posts: 1448
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: What is a model?

Postby Xenomortis » Fri Jul 26, 2013 7:51 am UTC

Spoiler:
I was going to use that joke, but I haven't actually used PHP, so it'd feel wrong.
Image

User avatar
Link
Posts: 1407
Joined: Sat Mar 07, 2009 11:33 am UTC
Location: ᘝᓄᘈᖉᐣ
Contact:

Re: What is a model?

Postby Link » Fri Jul 26, 2013 11:11 am UTC

You, sir, name? wrote:Python isn't poorly designed, not like PHP. Python is like a swiss army knife--it can do a lot, but its got a consistent theme. Although some would argue that it's support for functional programming is a mistake or out of place. But that is nothing. PHP plays in a different league altogether. It is notoriously badly designed, in a multitude of ways best explained in the classic essay PHP: A fractal of bad design.

Well fuck me. I knew PHP was bad, but that makes it look as if the developers actually put a lot of effort into making it as horrible as possible while still being marketable.

User avatar
Xenomortis
Not actually a special flower.
Posts: 1448
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: What is a model?

Postby Xenomortis » Fri Jul 26, 2013 11:27 am UTC

Link wrote:Well fuck me. I knew PHP was bad, but that makes it look as if the developers actually put a lot of effort into making it as horrible as possible while still being marketable.

No, that'd be C++.
Image

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: What is a model?

Postby korona » Fri Jul 26, 2013 11:35 am UTC

sparkyb wrote:No one has mentioned JavaScript. I loath the design/model of JavaScript even more than PHP or Perl. Similarly to Perl, JavaScript does have a definite model, but it's just not one I like. Perl's biggest problem is syntax, but operationally it works like most things. JavaScript's syntax is reasonable, but its prototypical inheritance model is really counter-intuitive. I can't ever remember how it works or how to do anything in that language, and from what I can tell from all the JS code I've read, no one else can agree on the right way to do stuff either. When your language needs an apologist book called "JavaScript: The Good Parts" to teach that the language isn't all bad, so long as you ignore certain bad parts, that's when you know you have problems.

JavaScript has many convenient features. I code almost all non-performance-critical things I write in JavaScript using node.js. It's design is actually clearer than Python's.
JavaScript has dynamic non-class based objects, first class functions, closures and prototypes. Prototypical inheritance is MUCH more convenient than class based inheritance. Its even powerful enough to fully simulate class based inheritance. "no else one can agree on the right way to do stuff" because the language is so flexible that there are multiple good ways to do stuff. For example classes can be simulated in multiple ways. You could use the classical new operator, something like Object.create) or a constructor function that creates a closures to contain the object's fields, etc.
In fact there are only two "Bad Parts" in the JavaScript core language (the in-browser implementations contain more hacks) and both of them will be fixed in future releases. The first one is the "with" statement and the second one is the fact that non-declared variables become global by default. A minor thing I don't like is that JavaScript's syntax is a bit loose, for example semicolons before closing brackets can be omitted.

EDIT: C++ also has a clear strategy. That is: If a feature is powerful i.e. will be able to significantly improve performance or development time we add it to the language. In my not so humble opinion C++ is THE most powerful language. It may be complicated but it is also incredible powerful.

wumpus
Posts: 546
Joined: Thu Feb 21, 2008 12:16 am UTC

Re: What is a model?

Postby wumpus » Fri Jul 26, 2013 3:13 pm UTC

WanderingLinguist wrote:Have you even used Objective-C? It's a strict superset of C, meaning that there are no compatibility sacrifices whatsoever. C programs run just fine under Objective-C without any modification. (The same cannot be said of C++, which did sacrifice compatibility).


No, I haven't used objective-C. Since C++ started out as a pre-processor of C, I can only assume that this is only true of later C++ editions. I quickly understood that learning C++ was going to a huge undertaking (compared to the tiny C language) and that if I learned to wrap C++ libraries I would be happy (and ignored the rest).

You, sir, name? wrote:Python isn't poorly designed, not like PHP. Python is like a swiss army knife--it can do a lot, but its got a consistent theme.


My issue was entirely with Python 3.0. I find python well designed and that design fits together amazingly well. The catch is that it always assumed a number of things about strings (ASCII, fixed length, able to use as raw bytes to send to C routines, etc.) that were all broken in Python 3.0. I'll have to go back sometime and see if the bytes datatype becomes somewhat more sane - it had broken most of the zen of python and certainly was special cased beyond the call of duty. I couldn't get it to do *anything* but convert back and forth into types of unicode.

Ben-oni
Posts: 278
Joined: Mon Sep 26, 2011 4:56 am UTC

Re: What is a model?

Postby Ben-oni » Fri Jul 26, 2013 6:26 pm UTC

wumpus wrote:
WanderingLinguist wrote:Have you even used Objective-C? It's a strict superset of C, meaning that there are no compatibility sacrifices whatsoever. C programs run just fine under Objective-C without any modification. (The same cannot be said of C++, which did sacrifice compatibility).


No, I haven't used objective-C. Since C++ started out as a pre-processor of C, I can only assume that this is only true of later C++ editions. I quickly understood that learning C++ was going to a huge undertaking (compared to the tiny C language) and that if I learned to wrap C++ libraries I would be happy (and ignored the rest).

You, sir, name? wrote:Python isn't poorly designed, not like PHP. Python is like a swiss army knife--it can do a lot, but its got a consistent theme.


My issue was entirely with Python 3.0. I find python well designed and that design fits together amazingly well. The catch is that it always assumed a number of things about strings (ASCII, fixed length, able to use as raw bytes to send to C routines, etc.) that were all broken in Python 3.0. I'll have to go back sometime and see if the bytes datatype becomes somewhat more sane - it had broken most of the zen of python and certainly was special cased beyond the call of duty. I couldn't get it to do *anything* but convert back and forth into types of unicode.


The way a language starts is usually irrelevant to what that language becomes. C++ isn't just a mishmash of random/interesting/useful features. They go together in a very elegant manner. While it is a large language, IMHO it's worth learning how the features interact, and why the language architects chose the ones they did.

As for strings in Python 3.0, I think you're misunderstanding what a string is. A "string" means a string of characters. A character is not a byte. The character encoding is not guaranteed, and is certainly not guaranteed to be ASCII. In particular, a "string" is not a C-string.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: What is a model?

Postby EvanED » Fri Jul 26, 2013 7:32 pm UTC

Ben-oni wrote:As for strings in Python 3.0, I think you're misunderstanding what a string is. A "string" means a string of characters. A character is not a byte. The character encoding is not guaranteed, and is certainly not guaranteed to be ASCII. In particular, a "string" is not a C-string.
Yeah, I agree here, though it's moving off-topic. IMO conflating a sequence of bytes with a character string is perhaps the worst legacy of C in a list of bad choices, and Python 3 splitting them up is the right thing to do.

I don't deal with that sort of thing enough to know whether Python 3 did them in a correct way or poorly, and I've heard complaints that there were some problems in 3.0-3.2 that were improved a lot in 3.3. So I can't say that they started broken and fixed things, and it's theoretically possible they started broken and broke things more. But they did not violate "if it ain't broken don't fix it", because it definitely started off broken.

User avatar
Xanthir
My HERO!!!
Posts: 5413
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: What is a model?

Postby Xanthir » Fri Jul 26, 2013 7:36 pm UTC

Indeed. You can easily convert a string into a sequence of bytes in Python 3, using the bytes() or bytearray() constructor. Just pass in the string and the desired encoding.

It's Python 2 that totally fucked up strings, since it started with the assumption of ASCII (that is, a "string" is a sequence of bytes, or a C string) and then bolted unicode (where a string is a sequence of code points) onto the side later. Python 3 swaps things, where strings are sequences of code points, and then you can turn them into bytes explicitly via an encoding.

[quote=EvanED]But they did not violate "if it ain't broken don't fix it", because it definitely started off broken.[/quote]
Hallelujah. My most recent Python2 project includes a "fuckunicode" module, which consists solely of the function u(), which bashes anything you pass to it into unicode. Before this, I was *constantly* getting encoding errors, which are impossible to figure out.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

lgw
Posts: 437
Joined: Mon Apr 12, 2010 10:52 pm UTC

Re: What is a model?

Postby lgw » Sat Jul 27, 2013 2:44 am UTC

Trying to circle back to the topic: C++ confuses people because it is the union of 2 models.

There's a truism that every sufficiently large C project reinvents C++. There's this large set of problems that you always seem to end up solving some subset of in any complex "real world" C project, that aren't the actual problem you're trying to solve. One part of C++ is to add language support for that set. Need to make sure every temporarily-allocated resource is freed? Need to allocate memory in the very special way you should in an appliance? Would it help to have classes and namespaces just so half of every name isn't a set of prefixes? Want to make sure callers don't forget to check return codes and errors are propagated up the stack? Big C projects run into these sorts of problems, and it's nice to just use language built-ins instead of rolling your own bugs. Almost no one does this, because it's not obvious what each language feature is for until after you've rolled your own solution. (About half of this stuff is also natural in high level languages, while the other half really isn't.)

The other model is the coding style that's quite similar to Java and C# (but possible in C++ before either language existed). Almost no one does this, because people always seem to bring a C mindset to C++, instead of seeing it as a way to write elegant code close to the metal.

The biggest problems with C++ is that most coders break the model, because it's not obvious what all the cruft in the language is for, and it's not obvious how to do anything right. That makes it an experts-only language that, in business, experts often dread because they know they'll spend all day fixing other people's misunderstandings.

So what's a model? A model is the abstract representation of a real problem that you're trying to solve. There are different ways to model a problem, and a particular approach to solving a problem may fit well with one model and "break" another, even though they model the same thing. Just like a given style of programming may flow naturally and elegantly in one programming language, and be endless frustration in another. Stick to stuff that's natural to express in your model.
"In no set of physics laws do you get two cats." - doogly

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: What is a model?

Postby korona » Sat Jul 27, 2013 10:44 am UTC

lgw wrote:There's a truism that every sufficiently large C project reinvents C++.

See GObject, Netscape Portable Runtime, implementation of drivers in the linux kernel. That are just the three projects that I remember without thinking too long. All three implement a C++ like object model to some extend.

User avatar
Cleverbeans
Posts: 1378
Joined: Wed Mar 26, 2008 1:16 pm UTC

Re: What is a model?

Postby Cleverbeans » Sat Jul 27, 2013 8:24 pm UTC

It's like a model airplane, but made of algorithms instead of material objects. Generally a program is designed to solve some real world problem, but it would be too hard computationally to simulate the real world entirely, so we just simplify the problem by forgetting some of the details and model it accordingly. Since a model airplane can't fly something is lost from the original, but if the purpose is merely to visually inspect the airplane then it's enough. The issue is then choosing what is required for the model you're making, and not making anything extraneous to the problem, then organizing all the pieces and gluing them together.

If you play an isometric perspective video game like Starcraft 2 or League of Legends, you can almost see a computer version of like a tabletop game, with computer rendered model figures, and landscapes all digitally painted and colored up. The model ignores normal physics like gravity which are outside game's ruleset and only considers what's possible within the simulation. Other problems won't have such a clear real world analogy, but the principles of ignoring the information that is irrelevant to the problem you're solving is a consistent theme.
"Labor is prior to, and independent of, capital. Capital is only the fruit of labor, and could never have existed if labor had not first existed. Labor is the superior of capital, and deserves much the higher consideration." - Abraham Lincoln

User avatar
Jplus
Posts: 1721
Joined: Wed Apr 21, 2010 12:29 pm UTC
Location: Netherlands

Re: What is a model?

Postby Jplus » Sun Sep 01, 2013 1:30 pm UTC

EvanED wrote:There are also places where two language features can interact poorly or surprisingly. (Those two adjectives are closer than you may think right now. :-)) It may be that either one is fine on its own, but when you put them together, there may be something like emergent behavior that makes predicting what happens difficult. C++ probably has some zingers like this, but I'm actually blanking right now and can't think of a good example.

Dependent name resolution is prone to produce very complicated and intimidating compiler errors when interacting with several other language constructs (on the condition that you did something wrong of course), including const-qualified member functions. The first time I ran into this I've been banging my head into my keyboard for days until an expert helped me out.

Xenomortis wrote:
Link wrote:Well fuck me. I knew PHP was bad, but that makes it look as if the developers actually put a lot of effort into making it as horrible as possible while still being marketable.

No, that'd be C++.

I hope everyone understands this is satire.

korona wrote:EDIT: C++ also has a clear strategy. That is: If a feature is powerful i.e. will be able to significantly improve performance or development time we add it to the language. In my not so humble opinion C++ is THE most powerful language. It may be complicated but it is also incredible powerful.

Actually, if a feature is powerful it still isn't necessarily added to the language, because library implementations are preferred if possible. There's also a strong emphasis on existing practice.

I somewhat agree to your sentiment about C++ being the most powerful. Semantically speaking it isn't any more powerful than D, Haskell or Ocaml (and perhaps one or two languages that I don't know about), but among these it has the leanest runtime ("closest to the metal" although that's a misleading phrase) and it offers the greatest number of options for resource management (though D still seems to be pretty close in this aspect).
Some languages are also very powerful but very different, for example Forth and relatives and Lisp. C++, Forth and Lisp are so different that I find it hard to compare them by power semantically. But it's true that C++ offers the best performance among them.
Because of the market share C++ also has the greatest number of libraries available among all of these languages.

lgw wrote:Trying to circle back to the topic: C++ confuses people because it is the union of 2 models.

There's a truism that every sufficiently large C project reinvents C++. [...]

The other model is the coding style that's quite similar to Java and C# (but possible in C++ before either language existed). [...]

The biggest problems with C++ is that most coders break the model, because it's not obvious what all the cruft in the language is for, and it's not obvious how to do anything right. That makes it an experts-only language that, in business, experts often dread because they know they'll spend all day fixing other people's misunderstandings.

[...]

While I agree most programmers tend to go against the "true spirit" of C++, I don't agree that the C++ model is a union of the two models that you describe, especially not the second. C++ has a fairly unique coding style of its own (or actually, a multitude of related coding styles) so if people bring a style from another language it's basically always "wrong". In addition beginners are always "wrong" and C++ is a language in which you stay a beginner for a long while.
"There are only two hard problems in computer science: cache coherence, naming things, and off-by-one errors." (Phil Karlton and Leon Bambrick)

coding and xkcd combined

(Julian/Julian's)

lgw
Posts: 437
Joined: Mon Apr 12, 2010 10:52 pm UTC

Re: What is a model?

Postby lgw » Fri Sep 06, 2013 9:24 pm UTC

Jplus wrote:
lgw wrote:Trying to circle back to the topic: C++ confuses people because it is the union of 2 models.

There's a truism that every sufficiently large C project reinvents C++. [...]

The other model is the coding style that's quite similar to Java and C# (but possible in C++ before either language existed). [...]

The biggest problems with C++ is that most coders break the model, because it's not obvious what all the cruft in the language is for, and it's not obvious how to do anything right. That makes it an experts-only language that, in business, experts often dread because they know they'll spend all day fixing other people's misunderstandings.

[...]

While I agree most programmers tend to go against the "true spirit" of C++, I don't agree that the C++ model is a union of the two models that you describe, especially not the second. C++ has a fairly unique coding style of its own (or actually, a multitude of related coding styles) so if people bring a style from another language it's basically always "wrong". In addition beginners are always "wrong" and C++ is a language in which you stay a beginner for a long while.


My biggest complaint about real-world C++ code is "C programmers", who know C very well but reject most of the added features in C++. Specifically, exceptions and RAII. Done right, C++ code looks quite similar to C# code from across the room. It's not cluttered with error-checking after every function call, and it's not "allocate at the top, free at the bottom, never return from the middle" the way good C code is. If you write C-style code in a C++ compiler, you break the model: none of the standard library stuff works the way you want it to. I've seen very large code bases that were nearly unmaintainable because of this problem, and Google is seriously struggling with it right now.

IMO, good C++ code should mostly look like good C# code, except where you're doing that stuff you can't do in a managed language, where you need the other model.
"In no set of physics laws do you get two cats." - doogly

Bryce1
Posts: 16
Joined: Thu Aug 22, 2013 9:30 am UTC
Location: United States

Re: What is a model?

Postby Bryce1 » Tue Sep 10, 2013 10:41 am UTC

The Model: this is where you should keep your data model, the algorithms. For example if you write a spreadsheet application, you would keep the data structure of your spreadsheet. You would have the computation engine in your model, you would have the code to save and load your spreadsheet in your model. These model class could potentially be reused in other applications, for example if you have code to do compression of data.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 3 guests