Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-8081-

My OO...

Name: Anonymous 2011-12-13 3:19

...it's violated!

http://programmers.stackexchange.com/questions/17031/when-c-handles-pop-in-your-c-code-and-break-your-pretty-oo-design

Anime avatar. Passive-aggressive rant. Autismal as fuck. That's gotta be someone from /prague/, amirite?

Name: Cudder !MhMRSATORI!FBeUS42x4uM+kgp 2011-12-13 4:14

That is either a very good piece of satire or written by some idiot who has truly been brainwashed by OOP shit. I've seen so many of the latter that it's easy to tell at a glance.

http://www.codinghorror.com/blog/2004/09/why-objects-suck-revisited.html

 All you should be thinking about when designing/writing code is
1. Does it work?
2. Is it simple?
3. Is it efficient?

OOP was created as nothing more than a convenience for using structures and functions that operate on them. Anyone who does not understand that and worships it like it's some deity that provides enlightenment from all programming problems is a brainwashed idiot.

Name: Anonymous 2011-12-13 4:52

>>2

I think you're missing something

"is it safe?"

Say I'm writing a graphics library, and I don't want certain parts of my window class to be touched, as letting the user fuck around with them willy nilly will crash the program (however they need to be there). Things like, oh I don't know, the dimensions of the window. Sure you can ask for it, but changing what the program thinks is the dimensions and what is actually the dimensions would be just plain silly.

Here comes the OO programmer. He declares the dimensions of the window private, and creates getter functions in case the programmer needs to know what they are, but makes no possible way of changing them outside of the constructor function.

Name: F r o z e n V o i d !!mJCwdV5J0Xy2A21 2011-12-13 5:02

OOP can be always abstracted out: you can't do the same with functions.
The proper way to do it >>3 is to make window_class encapsulated into a function which maintains the window object via a standard API you define. The window Object itself should not be linked to the function: it would be decoupled from the object(which serves as data storage).

Name: Anonymous 2011-12-13 5:09

>>3
If your library is used by a drooling retard, it will crash anyway.

Private methods and variables are still just documentation that is to certain extent enforced by the compiler. By fiddling bits or manipulating headers that come with the library its user can do anything. Anything! With C libraries these things tend to be written in the comments if it's not evident from the header files what you're supposed to touch. Very often it is evident.

You can expect the user of your library can read and understand the code he's using. If he is not willing to, it's his own god damn fault.

Name: Cudder !MhMRSATORI!FBeUS42x4uM+kgp 2011-12-13 5:13

and I don't want certain parts of my window class to be touched, as letting the user fuck around with them willy nilly will crash the program
So what? If the user fucks up it's the user's fault.

Here comes the OO programmer. He declares the dimensions of the window private, and creates getter functions in case the programmer needs to know what they are, but makes no possible way of changing them outside of the constructor function.
*(((int*)pWindow)+2) = 9999;

Welcome to the real world.

Name: Anonymous 2011-12-13 5:17

Silly Cudder, puts a whitespace betwixt his name and the hash character.
That's not how you should trip on world4ch silly Cudder!

Name: Anonymous 2011-12-13 5:47

Filthy Cudder, puts a massive cock betwixt his buttocks.
That's not how you should trip on world4ch filthy Cudder!

Name: Anonymous 2011-12-13 6:11

>>2
JA;DR

Do you really think he is qualified to talk about the merits of OO, procedural programming?

Name: Anonymous 2011-12-13 9:43

This feels like a blog article, not a question. If you have a question, please make it more explicit and reduce the context to a minimum.

Name: Anonymous 2011-12-14 11:45

>>6
*(((int*)pWindow)+2) = 9999;
Weak typing is evil.

Name: Anonymous 2011-12-14 12:35

>>11
Weak typing is great.

Name: Anonymous 2011-12-14 12:39

pseudo-OOP : OpenGL

what

Name: Anonymous 2011-12-14 12:40

I have no strong feelings one way or another toward weak typing, but I can't wait for the 'weak typing is shit', 'if it's not weak typing, it's shit', 'jews invented weak typing' and other 'hax my weak typing'-type posts.

Name: Anonymous 2011-12-14 13:14

>>14
Only because you don't understand programming.

Name: Anonymous 2011-12-14 13:29

>>12
Yes, for non-programmers.

Name: Anonymous 2011-12-14 13:47

>>14
Here's how weak typing kills safety in your programs:

#include <iostream>
 
class Wallet {
        public:
                int money;
                Wallet() { money = 100; }
                void setMoney(int pounds) { money = pounds; }
};
 
class MyWallet : private Wallet {
        public:
                int getMoney() { return money; }
};
 
int main() {
        MyWallet *wallet = new MyWallet;
        reinterpret_cast<Wallet*>(wallet)->setMoney(9000);
        std::cout << wallet->getMoney(); // Output: 9000
        return 0;
}

Name: Anonymous 2011-12-14 14:19

>>17
You are implying that strong typing prevents this, but it doesn't. A malicious programmer (which is clearly what would be needed for your example) can directly modify application memory in any number of ways.

Name: Anonymous 2011-12-14 14:25

>>17,18
This is exactly the problem with strong typing.  It creates a false sense of "safety" without adding any safety at all.

Name: Anonymous 2011-12-14 14:25

Name: Anonymous 2011-12-14 14:31

>>18
In your case it's not a language problem, it's problem of your OS which provides you direct access to the memory. Strong typing is also vulnerable to this kind of attacks (and it's very difficult to use them), but it eliminates problems like I showed above.

Name: Anonymous 2011-12-14 14:35

I read part of the URL as "when C handles poop in your code".
Do what you want with this information.

Name: Anonymous 2011-12-14 14:43

>>21
Strong typing
Fix: static typing

>>18,19
It'd be useful if you could provide examples of such tricks in a strongly typed language.

Name: Anonymous 2011-12-14 15:01

>>23
Of course strongly-typed languages for some weird reason tend to run in managed environments...

Name: Anonymous 2011-12-14 15:12

>>23
Trivially, http://www.haskell.org/ghc/docs/latest/html/libraries/base/Foreign-Ptr.html

If you start thinking about the kind of controls that would be needed to prevent this, it's inconceivable and won't be seen in our lifetimes.

Name: Anonymous 2011-12-14 15:20

>>25
I might add,

"You may want your programming language to be strongly typed. Just about every other force in the computer wants it weak."

Name: Anonymous 2011-12-14 18:07

>>25
It is part of the foreign function interface you massive faggot. Of course it is going to be unsafe.

Jesus CHRIST /prog/ is filled with fucking retards lately.

Name: Anonymous 2011-12-14 19:02

>>27
Wait, are you saying that strongly typed languages are safe?  You really need a counterexample?  Have you ever used C or C++ or C#?

/prog/ is filled with fucking retards lately.
Well, head back to /vp/ then.

Name: Anonymous 2011-12-14 19:12

>>27,28
... or are you doing that thing where you pretend like there's a difference between "strong" and "static" typing?  Yeah, there's a difference, but generally, when someone says "strongly typed," they mean the equivalent of statically typed.


int func(int a) { return a + 1; }

int main(int argc, char **argv)
{
    func("string");
    return 0;
}


error C2664: 'func' : cannot convert parameter 1 from 'const char *' to 'int'

That's what people usually mean by "strongly typed," and it doesn't make the world any safer.

Name: Anonymous 2011-12-14 19:29

The "safe" and "unsafe" distinctions are all bullshit anyway.

It's better to think of it as "making sure the program works as it should under all conditions of input" than "programming safely".

Part of the reason why computers are so powerful is because data is entirely dependent upon its interpretation, and we should respect that fact and not try to subvert it.

Name: Anonymous 2011-12-14 20:00

>>30
"making sure the program works as it should under all conditions of input"
But that's the whole point; static (or "strong") typing doesn't even do that.  Nothing does that.  It's equivalent to solving the halting problem.

Name: Anonymous 2011-12-14 20:49

>>28
C and C++ are not strongly typed languages.

Name: Anonymous 2011-12-14 22:14

its more like dynamically typed, where all the types coerce somehow to nonsense ints.

Name: Anonymous 2011-12-15 1:19

>>27
That's precisely my point. The idea that we should, for some reason, protect code from it's own developers is ludicrous. That people think strong typing will help effect such protections is at best comical, at worst incredibly dangerous.

Name: Anonymous 2011-12-15 1:22

>>34
Please die.

Name: Anonymous 2011-12-15 1:25

>>35
A well articulated argument!

Name: Anonymous 2011-12-15 1:27

>>36
It is all that strawman deserved.

Name: Anonymous 2011-12-15 2:09

>>34
So what danger does strong typing impose?

Name: Anonymous 2011-12-15 2:12

>>38
That some sepples programmer might write something that works and is maintainable, apparently.

Name: Anonymous 2011-12-15 5:15

>>38
Perhaps a false sense of security. With a dynamic language behavioural forces are exerted to rigorously test and that may end up quite comprehensive, whereas a program that gets types checked and an occasional runtime testing will not exert as much pressure to establish a test suite.

Name: Anonymous 2011-12-15 6:13

>>40
That's precisely my point. The idea that we should, for some reason, force developers to test their own code is ludicrous. That people think dynamic typing will help effect such incentives is at best comical, at worst incredibly dangerous.

Name: Cudder !MhMRSATORI!FBeUS42x4uM+kgp 2011-12-15 7:21

>>41
Learn formal verification.

Name: Anonymous 2011-12-15 7:55

embrace chaos

Name: Anonymous 2011-12-15 8:03

Woho, I got dubs!

(I think...)

Name: Anonymous 2011-12-15 8:04

emrase my dik

Name: Anonymous 2011-12-15 10:12

>>32
Says you.  Most people, including Wikipedia, say otherwise.  "Strongly typed" and "weakly typed" aren't well defined.  Well, not in a way that's widely accepted, anyway.

Name: Anonymous 2011-12-15 10:19

>>46
The only reason they aren't well-defined is because so many sepples fags insist it is a strongly typed language. They're wrong, and C++ is garbage. It's like saying evolution isn't well-defined or widely accepted because there are a bunch of creationist idiots.

Name: Anonymous 2011-12-15 11:15

>>47
No, it isn't like that at all, and you're no longer credible or welcome in this thread.

Name: Anonymous 2011-12-15 11:20

>>48
Lisp has stronger typing than C++. Deal with it.

Name: Anonymous 2011-12-15 11:25

>>49
That doesn't mean that C and C++ aren't strongly typed.  Deal with it.

Name: Anonymous 2011-12-15 11:32

>>50
They aren't. Look at the wikipedia page you mention. Here are the criteria mentioned:
* Absence of unchecked run-time type errors. C++: nope lol.

* Strong guarantees about the run-time behavior of a program before program execution, whether provided by static analysis, the execution semantics of the language or another mechanism. C++: nope lol.

Type safety; that is, at compile or run time, the rejection of operations or function calls which attempt to disregard data types. ... C++: partial credit, only because I omitted the rest of the paragraph.

* [Static typing bullshit omitted]

* Fixed and invariable typing of data objects. The type of a given data object does not vary over that object's lifetime. C++: nope lol.
* Omission of implicit type conversion, that is, conversions that are inserted by the compiler on the programmer's behalf. C++: nope lol

* Disallowing any kind of type conversion. Values of one type cannot be converted to another type, explicitly or implicitly. C++: nope, lol.

* A complex, fine-grained type system with compound types.
Brian Kernighan: "[..]each object in a program has a well-defined type which implicitly defines the legal values of and operations on the object. The language guarantees that it will prohibit illegal values and operations...
C++: nope lol

Name: Anonymous 2011-12-15 13:56

>>51
STOP BEING STUPID (not an insult -- I actually want you to take a moment and make an effort to be less stupid, for everyone's sake)

Those are examples under a heading that reads:
Some of the factors which writers have qualified as "strong typing" include:

They are listed to illustrate the fact that there is no widely accepted, consistent definition.

Right above that heading, there's a handy little table that looks like this:

┌───────────────────────────────────┬────────────────────────────────┐
│            Weak Typing            │         Strong Typing          │
├───────────────────────────────────┼────────────────────────────────┤
│Perl, PHP, Rexx, JavaScript, BASIC │ Java, C, C++, Python, C#, Vala │
└───────────────────────────────────┴────────────────────────────────┘


You can do this!  I believe in you!

Name: Anonymous 2011-12-15 15:51

>>52
Weak Typing
BASIC

Stop being retard. BASIC is like Haskell - strong and static:
http://en.wikipedia.org/wiki/Visual_basic
Typing discipline     Static, strong

Name: Anonymous 2011-12-15 16:29

>>52
The point, you dunce, is that in almost any sense in which one uses ``strong typing'' your beloved sepples fails hard, a feeling with which I am sure you are familiar.

Name: Anonymous 2011-12-15 17:50

>>54
I really tried, but you're stuck on your feelings being hurt, or something.  All I can do is refer you to the obvious, which is pointed out several times in this thread, probably most clearly here: >>29

I don't like C++ much, so your big nasty diss on my beloved language is misplaced.  But even my dislike of it (and yours) isn't enough to make it a weakly typed language.

Name: Anonymous 2011-12-15 17:53

>>53
There are a lot of BASICs in the world, and Visual Basic is probably the least "BASIC-like" of all of them.  But if you feel strongly about it, then you should go and fix the Wikipedia article.

Name: Anonymous 2011-12-15 19:04

>>55
Way to talk out of both sides of your mouth. First it is poorly defined (because, well, there's no consensus, which is an interesting definition of ``being well-defined''), and second it is strongly typed anyway. There are words for such arguments but a lesson in vocabulary will not further the conversation.

Sorry, but C++ isn't a strongly typed language. C is barely typed at all, and that's only if we follow the most trivial definition of "typing" to mean something like "there are keywords for types." C++ improved this not at all, because of course even though everything C is evil and wrong and dangerous, it should be compatible with C anyway.

I'm sure if one's interest is in defending C++ as a ``strongly typed language with support for object-oriented programming'' then one could come up with all matter of snake oil to rub on the warts. But those of us without any particular attachment to C++ can see plainly that C++'s types are approximately comments that are read by a compiler and little more. This is due strictly to its C roots, and C gets it from trying to be something like a portable assembler, and assemblers aren't generally typed for good reason. (Though there are of course typed assembly languages. For good reason.)

It is shameful that languages without explicit type annotation have better behavior than a language with it. Shameful. To then turn around and actually call such a language ``strongly typed'' for whatever non-trivial meaning is absolutely disgusting.

Name: Anonymous 2011-12-15 19:21

>>52
That table is nonsense and seems to be built on the idea that weak typing precludes static typing. Not only is C weakly typed, it behaves differently than stated:

concatenate(a, b) # not a type error, probably a segfault
add(a, b)         # not even wrong, just semantically different


You can even change "2" to 2.0, and it moves from the right column to the left column.

Name: Anonymous 2011-12-15 19:58

>>57
Look.  In perl, you can do this:


 $x = 5;
 $x = "string";


In C, you can't.  You have to explicitly type-cast or you get a compiler error.  In C++, the same is true for POD types and even classes, generally.  You can always circumvent the type system by casting, taking address-of, etc...  but that does not mean that the language is not strongly typed.

That's all there is to it.  It's "poorly defined" because there are many conflicting definitions for it.  But by the most commonly accepted definition -- which, from the beginning of this discussion, has been equivalent to "statically typed" -- C is absolutely, positively, "strongly typed."

You are confusing this extremely simple statement of a fact with "defending" a language which is misleading.  It's convenient to just assume that everyone who disagrees with you does so because they're in love with a particular language, but it seems like the reverse is true...  You want C or C++ to be weakly typed just because you hate it.  Being weakly typed isn't even necessarily a bad thing.  You calling C++ weakly typed wouldn't be an insult to the language even if it were true.

Name: Anonymous 2011-12-15 20:03

>>58
You can even change "2" to 2.0, and it moves from the right column to the left column.
NO!  This is 100% completely false, and your misunderstanding is apparently common to nearly every poster in this thread.

If you take the example on the right side of the table as C, then it would have to look like this:


int a = 2;
char *b = "2";
 
concatenate(a, b);
add(a, b);


See that?  Variables are declared with a static type.  Changing the first line to this:


int a = 2.0;


does not change a to type float.

Name: Anonymous 2011-12-15 20:06

>>59
You can always circumvent the type system by casting, taking address-of, etc...  but that does not mean that the language is not strongly typed.
In sepples fantasy land, sure.

``It's a great house! It's only missing a roof, but that's 5 out of six sides covered!!''

Name: Anonymous 2011-12-15 20:14

>>61
That's the point!  Yes, that would be a shitty house.  But it would still be a house.  Yes, C and C++ are shitty, but they are indeed strongly typed.  That doesn't make you any less of a man!

Name: Anonymous 2011-12-15 20:38

>>59
In C, you can't.  You have to explicitly type-cast or you get a compiler error.
int main()
{
    char * x;
    x = 5;
    x = "Hello";
    return 0;
}


GCC:
Compiling: main.c
main.c: In function 'main':
main.c:4: warning: assignment makes pointer from integer without a cast
Linking console executable: bin\baka1.exe
Output size is 25.11 KB
0 errors, 1 warnings


OpenWatcom:
Compiling: main.c
main.c(4): Warning! W101: Non-portable pointer conversion
main.c(4): Note! N2003: source conversion type is 'int '
main.c(4): Note! N2004: target conversion type is 'char *'
Linking console executable: bin\baka2.exe
Output size is 32.01 KB
0 errors, 3 warnings


Digital Mars:
Compiling: main.c
    x = 5;
         ^
main.c(4) : Error: need explicit cast to convert
from: int
to  : char *
--- errorlevel 1
1 errors, 0 warnings

Name: Anonymous 2011-12-15 20:38

I'M TYPING SO HARD RIGHT NOW

Name: Anonymous 2011-12-15 20:38

>>62
But it would still be a house.
Only if you live in sepples-land.

Name: Anonymous 2011-12-15 20:47

>>58,60
Ah, shit.  I just realized that I misread your example.  You're suggesting something more like this:


int a = 2;
float b = 2.0f;

add(a, b);


And you're right, that would be allowed by any C compiler I've ever used.  Yes, there are special rules for "arithmetic promotion."  It's still misleading to call that dynamic typing, though.  It amounts to some temporary anonymous variables to convert from float to int during the call to the function.  Yeah, believe me, I fully understand how shitty C is.  Still, shitty does not necessarily imply weakly typed.

Name: Anonymous 2011-12-15 20:51

>>66
Why are you so desperate to defend C on false grounds when it is a perfectly useable language? Not being strongly typed is only an insult if one is used to defend shit languages, of which C is not a member. C++, of course, is fucking trash and deserves heaps and stacks of scorn.

Name: Anonymous 2011-12-15 20:51

>>63
Thanks, but I don't think anyone needed you to go to all that trouble just to prove the statement.  Some compilers give you warnings and others give you errors.  Strictly compliant ones give you errors.

But more importantly, NO C compiler implicitly converts the string "Hello" into an integer.  If a compiler does actually generate code, you will (obviously) end up with the address of the literal in x.

Name: Anonymous 2011-12-15 20:53

>>67
Yeah, believe me, I fully understand how shitty C is.
Why are you so desperate to defend C

Name: Anonymous 2011-12-15 21:01

>>68
so, about that strong typing...

Name: Anonymous 2011-12-15 21:03

>>69
It's not strongly typed. That's not an insult, it is just life. The weaseling in this thread is totally ridiculous.

Name: Anonymous 2011-12-15 21:07

>>71
Well, ok.  You're free to choose to believe that it's dynamically typed.  And you're free to write int a = "2"; and pray to the magic typing unicorn that the value of 2 will actually end up in that variable.  And if you ever do actually use C one day, you can test your theory.  Until then, stick with your convictions.

Name: Anonymous 2011-12-15 21:18

>>72
And you're free to write int a = "2"; and pray to the magic typing unicorn that the value of 2 will actually end up in that variable.
It's cute that not only can you not actually succeed in your apologetics, you have to resort to made-up semantics for how you think I think C behaves to feel your hollow victory.

There's nothing wrong with C. It's just not strongly typed. That's not a complaint.

Name: Anonymous 2011-12-15 21:22

I feel C's typing reflects its low level assembler design as its types originally wasn't meant at all for safety but for specifying word size and register type behavior since the expression tree links are register bound. C++ can't have ML or Haskell-tier type safety and keep C compatibility.

Name: Anonymous 2011-12-15 21:32

Name: Anonymous 2011-12-15 21:38

>>66
Yes, there are special rules for "arithmetic promotion."
The distinction is useless (i.e. purely arbitrary) if you allow it for floats and not for pointers to char. This is why I'll tell anyone who says C isn't weakly typed they don't know C.

It's still misleading to call that dynamic typing, though.
It's not dynamic, it's static with an implicit conversion. Even C's explicit type conversions are not safe on the whole, esp. void.

Yeah, believe me, I fully understand how shitty C is.  Still, shitty does not necessarily imply weakly typed.
For one, I love C. There are a few things I wish were different but changes to the type system are very far down that list. I wouldn't call it shitty by any means. You've probably read those blog posts about "const poisoning" by Chicken Little—it's never difficult to resolve by those who actually write C without posting every challenge they encounter to their blog.

The 'strength' of the type system isn't a value judgment, it's a semantic one. The typing is weak because it's weakly enforced, in fact you won't get much weaker in a static language.

>>68
But more importantly, NO C compiler implicitly converts the string "Hello" into an integer.
#include <stdio.h>

int main(void) {
   printf("%d\n", 2 + "Hello");
   return 0;
}


You sure about that? Might want to check the assembly output.

Name: Anonymous 2011-12-15 21:49

>>76
You sure about that? Might want to check the assembly output.
Within the compiler, 2 + "Hello" is still a char *.

Name: Anonymous 2011-12-15 21:51

>>76
congrats you just printed out the pointer address

Name: Anonymous 2011-12-15 21:52

>>78
pointer address + 2 i should say *

also use %p or 2 + *"Hello"

Name: Anonymous 2011-12-15 21:58

>>78
Perhaps you should attempt to understand what this thread is about before responding.

Name: Anonymous 2011-12-15 22:00


x@debian:~/host/prog/p1$ gcc -S anus.c
x@debian:~/host/prog/p1$ gcc anus.s
x@debian:~/host/prog/p1$ ./a.out
Anus
0x400675
4195970
x@debian:~/host/prog/p1$ cat anus.s
    .file    "anus.c"
    .section    .rodata
.LC0:
    .string    "Anus"
.LC1:
    .string    "%p\n"
.LC2:
    .string    "Faggot"
.LC3:
    .string    "%d\n"
.LC4:
    .string    "Hello"
    .text
.globl main
    .type    main, @function
main:
.LFB0:
    .cfi_startproc
    pushq    %rbp
    .cfi_def_cfa_offset 16
    movq    %rsp, %rbp
    .cfi_offset 6, -16
    .cfi_def_cfa_register 6
    movl    $.LC0, %edi
    call    puts
    movl    $.LC1, %eax
    movl    $.LC2, %esi
    movq    %rax, %rdi
    movl    $0, %eax
    call    printf
    movl    $.LC3, %eax
    movl    $.LC4+2, %esi
    movq    %rax, %rdi
    movl    $0, %eax
    call    printf
    movl    $0, %eax
    leave
    ret
    .cfi_endproc
.LFE0:
    .size    main, .-main
    .ident    "GCC: (Debian 4.4.5-8) 4.4.5"
    .section    .note.GNU-stack,"",@progbits

Name: Anonymous 2011-12-15 22:15

>>77
Oh you mean an int? Just pass it to foo(int a).

Not only will the conversion be implicit, you'll be told as much during compilation.

Name: Anonymous 2011-12-15 22:20

>>81
32-bit system?

Name: Anonymous 2011-12-15 22:32

>>83

x@debian:~/host/prog/p1$ uname -a
Linux debian 2.6.32-5-amd64 #1 SMP Thu Nov 3 03:41:26 UTC 2011 x86_64 GNU/Linux

Name: Anonymous 2011-12-15 22:34

>>83
rax
32-bit system

If you're going to fail, at least try failing upwards.

Name: Anonymous 2011-12-15 22:53

>>84
I got different output. Thought that might be why.

>>85
I don't know asm.

Name: Anonymous 2011-12-15 22:57

Name: Anonymous 2011-12-15 23:00

>>84
My hostname is localhost.

Name: Anonymous 2011-12-16 0:00

>>87
I still don't know asm.

Name: >>86 2011-12-16 0:53

>>89
Stop that.

Don't change these.
Name: Email:
Entire Thread Thread List