20

Please, explain why and list which languages have the (mis)feature implemented As far you know.

Post what you consider a harmful feature, not what you dislike.

Maniero
  • 10,826
  • 14
  • 80
  • 133

30 Answers30

37

Register Globals in PHP

Information : http://php.net/manual/en/security.globals.php

This is by far the worst feature to be ever implemented for readability reasons and security reasons. Basicly all the GET parameter received are transformed into variables.

For example with this URL : /index.php?value=foobar

You can do the following :

<?php
echo $value; // return foobar
?>

When you are reading code, it is very confusing to know where the variable comes from.

Also if the feature is misused, it can lead to security hole. Here's a code example from php.net that shows how it can be misused :

<?php
// define $authorized = true only if user is authenticated
if (authenticated_user()) {
    $authorized = true;
}

// Because we didn't first initialize $authorized as false, this might be
// defined through register_globals, like from GET auth.php?authorized=1
// So, anyone can be seen as authenticated!
if ($authorized) {
    include "/highly/sensitive/data.php";
}
?>
HoLyVieR
  • 976
  • 1
  • 13
  • 16
  • Thats horrible. While I can understand the want, keeping it on by default made absolutely no sense – TheLQ Sep 10 '10 at 20:30
  • 14
    It should be noted and emphasized that register globals has not been enabled by default since PHP 4.2 (all the way back in 2000), is deprecated in PHP 5.3 (2009) and will be removed entirely in PHP 6, but people *still* keep going back to the "OMG register globals" well even after 10 years. –  Sep 14 '10 at 20:28
  • 1
    Pretty Hopeless PHP – Ming-Tang Sep 23 '10 at 22:57
  • @SHiNKiROU It's not hopeless, that feature was deprecated and will be removed in PHP 6. – HoLyVieR Sep 24 '10 at 03:35
  • 1
    It's not hopeless, it's just so far behind so many other languages that the only reason anybody uses it is because it was until recently a lot easier to get cheap webhosting for it than other languages. – intuited Oct 19 '10 at 07:40
22

Allow Null by default, the "trillion"* dollar mistake. Sorry Tony Hoare. Almost every language available on planet.

Tony Hoare explains

*I adjusted the expression coined by Tony Hoare to reflect actual loss on these days :-)

Maniero
  • 10,826
  • 14
  • 80
  • 133
  • This is not a feature or a mistake, but rather, a lack of feature. Having non-nullable reference types is not something you can lightly drop into a language; It requires a lot of thought and good design, and is very hard to do in a way that doesn't feel like fighting with the compiler. Spec# and Singularity show how hard it is. – imgx64 Sep 24 '10 at 05:21
  • @imgx86, no, it's definitely a mistake. Non-nullable reference types are a feature added in response to the null mistake to allow compatibility with a type system that ordinarily allows null. – Matt Olenik Sep 24 '10 at 14:19
  • @Kyralessa: Perhaps he wants to be sure that HoLyVieR gets the Populist badge? :-) I agree, it makes no sense to accept your own answer like this. – Macneil Nov 26 '10 at 18:00
18

C and C++ MACROS. If I ever have to see another compiler error due to someone choosing a standard function name for their macro which screws up my code I'm going to scream. Let's see the last offending one:

#define vector(int) new VARIANT[int];

Aaarg! What have you done with my STL vector!?

wheaties
  • 3,584
  • 22
  • 23
  • Namespacing is one of the things that makes typedefs and templates immediately more friendly. – Shog9 Sep 13 '10 at 19:01
  • 4
    Agreed, but only because modern languages have found replacements for the functionality of textual macros. Back when they were invented, macros were a Good Thing because compiler technology was so primitive. – dsimcha Sep 14 '10 at 04:26
  • where did you find this macro? – rwong Nov 02 '10 at 05:40
  • @dsimcha - I don't know about this. Lisp macros have been around for a long time. – Jason Baker Nov 26 '10 at 23:44
  • +1 For denouncing C++ macros, they are overused to the point where the entire code seems to be in shorthand. – Orbling Nov 27 '10 at 01:04
  • 2
    @Jason: I'm not knocking Lisp-style "real" AST macros, which are still useful and cool. I only hate C/C++-style macros that work purely at the textual level, have no concept of scope, allow one to create ridiculously leaky abstractions and obfuscated code, and can be completely made obsolete by more modern features, one of which, ironically, is "real" macros. – dsimcha Nov 27 '10 at 19:25
  • Macros are excellent feature in C. You just need to know how to use them. – StasM Dec 17 '10 at 20:17
  • #define true false – Quillion Jun 21 '12 at 12:40
14

Fallthrough by default in C and C++ switch statements.

Niall C.
  • 879
  • 2
  • 11
  • 16
  • 18
    This is always a *helpful* feature in all of the code I've written. How is this a misfeature? – greyfade Sep 10 '10 at 14:24
  • 1
    This has gotta be one of my *favorite* parts of `switch`... Without fallthrough, there are far more flexible ways of accomplishing the same thing. – Shog9 Sep 13 '10 at 19:00
  • 6
    @greyfade: It's helpful until you forget the `break` statement, or someone adds a case between two cases (or re-orders them), not noticing there was fall-through between them. I don't see any way that fallthrough is better than the C# way of requiring either a break or goto case, etc. – Tim Goodman Sep 14 '10 at 15:57
  • 9
    Duff's Device scoffs at your impunity! – Jesse C. Slicer Sep 14 '10 at 22:20
  • 3
    i agree. By default is not a good feature. –  Sep 18 '10 at 05:45
  • Without fallthrough, things like daysInMonth() would take waaaay more code. – Christian Mann Sep 24 '10 at 00:21
  • 11
    Does no one read? He said fallthrough BY DEFAULT – Matt Olenik Sep 24 '10 at 14:20
  • I use it a lot - but always comment fallthroughs. I don't see the harm. – Tim Sep 24 '10 at 18:05
  • 3
    Fallthrough is an excellent feature; having it as a default rather than requiring it to be told to do it isn't. However... so many heavily used C-derivative languages do it that programmers are used to it and should be especially aware of the risk. I'm not a fan of the compiler hand-holding and nannying the coder. – Orbling Nov 27 '10 at 01:09
13

Implicit type conversions when the types being converted between have no obvious relationship. For example, converting a random, non-numerical string into an int, like in PHP.

Chinmay Kanchi
  • 6,173
  • 2
  • 39
  • 51
  • 7
    Should be noted that once you get your head around it, this sort of thing becomes a non-issue. It's only really a problem if you don't do any checks in critical areas for user entered values, but is infinitely useful if, say, you know something will be a number, but comes as a string. For example, a field from a DB will likely be returned as a string, and you don't want to worry about casting it. – Tarka Sep 24 '10 at 19:27
  • 2
    @Slokun: Can you come up with a better example? Why store integral values in a db using a string type? – Steven Evers Oct 02 '10 at 02:58
  • @SnOrfus Getting a number passed in a URL, user input, functions, and other things common to non-statically typed languages. – TheLQ Oct 03 '10 at 20:30
  • This is also a problem in C, since a quoted string's value is a pointer, which can be converted to an integer, and this can make constructs that look like they might make sense compile properly but produce nonsense. In C++, you can define conversion functions with the keyword `explicit`, which stops implicit type conversions, but there's still problems. – David Thornley Oct 04 '10 at 15:23
  • @TheLQ: If it's user input, you have to validate it to figure out if it's a number. Like @Slokun said. If you're reading data from a file, you can kind of expect numeric data to be where it's supposed to, but having an exception get raised in the case of disk corruption is often better than just having a random `0` for some value. – intuited Oct 19 '10 at 07:48
12

goto: although ok in rare cases, it is more often misused and leads to hard to read programs.

Brian R. Bondy
  • 7,067
  • 32
  • 53
11

NONE

Just because a feature gets misused frequently does not make it harmful.

IMHO the entire "is considered harmful" is the Reductio ad Hitlerum of programming language discussions.

Most, if not all, of the "harmful" features have, or had originally, a very valid use case or are simply convenience methods in the first place. It is up to the developers to understand the pros and cons and code accordingly.

If your questions was meant to be something along the lines of "what language features have common pitfalls or unfortunate side-effects" my answer would be different.

[edit] To be clear: I do not mean the continued use of deprecated methods. If the developers are depreciating/removing a feature you should use the replacement. I am referring to concept that a current part of the language is considered harmful because some do not like what it encourages or the trade-off involved in using it that many people discuss.

Timwi
  • 4,411
  • 29
  • 37
Bill
  • 8,330
  • 24
  • 52
  • 13
    I disagree, a good counter example is my answer. PHP register global was just bad, no mater how you use them. This is why it has been deprecated and strongly advise to never use on older version of PHP. – HoLyVieR Sep 13 '10 at 18:23
  • Had to read up on that one, but the link in the answer that mentions it agrees with my point "This page will explain how one can write insecure code with this directive but keep in mind that the directive itself isn't insecure but rather it's the misuse of it." The link also mentions it is depreciated, which is not what I was meaning, so I edit accordingly. – Bill Sep 13 '10 at 21:00
  • 5
    +1 Put in wrong hands, any language construct is harmful. – mouviciel Sep 14 '10 at 20:37
  • @mouviciel - that is probably the most concise way to put the point – Bill Sep 14 '10 at 21:38
  • 5
    Good point... even if 95% of gotos are bad, the feature itself is still worth having for the other 5% – eds Sep 14 '10 at 23:53
  • HoLyVieR: i agree. good example. Also with gotos, i believe if there were additional language constructs you can get rid of all reasons to use them. Also i believe there are ways to get rid of MANY macros (but not all, even tho i said all gotos can be gotten rid of) –  Sep 18 '10 at 05:44
  • 1
    I think it's more like putting the ejector seat button next to the radio on/off button. The feature itself might not be bad, but not preventing harm by accidental use of it is. – LennyProgrammers Sep 24 '10 at 08:54
  • I am all for making the dangerous stuff spew warnings or be a lot harder to get at. I just find it backward that some people would presume to remove a feature just because it has bit them too many times without proposing an alternative that performs the same function with the same level of execution efficiency. I have often thought that in many of these situations it would be useful to have an "unsafe" namespace like some of the .net languages have for unmanaged and move all of the questionable functions in there to make it VERY obvious, but I would never remove them without a replacement. – Bill Sep 24 '10 at 12:58
  • 1
    I think this is the programming equivalent of "guns don't kill people, people do". – Orbling Nov 27 '10 at 01:11
  • Excellent point, I wish I had a +10 vote :) – StasM Dec 17 '10 at 20:19
  • "fool-proofness" has no value? Every manager knows he will have morons or drunk programmers working on his code at some point. – Pavel Radzivilovsky Jan 24 '12 at 18:39
  • @Pavel I agree, and in 99% of cases I would fxcop the crap out of anyone using a goto on my projects but that still does not make me want the word removed. Also, a fool proof programming language would either be nearly useless it had so few functions or be completely underestimating the scale of fools' power to do the foolish. – Bill Jan 26 '12 at 00:01
7

Although some folks disagree with the man or various things he says, a lot of Douglas Crockford's JavaScript: The Good Parts is basically this question applied to JS. Amongst Crockford's complaints:

  • Global scope by default for everything (DC shows how to use function/objects as namespaces and scope delimiters to wrangle this in.)

  • Statements like with, whose failure behavior is to define things at the global namespace. (Gah! Its like the JS motto is if you fail, then fail as hard as possible!)

  • Unexpected behavior with the == operator, which basically requires you to always use the === operator.

  • Semicolon insertion.

Really a whole lot of JS should be considered harmful, maybe even the whole language, but the good parts are just so darn good that it kind of makes up for it (at least for me.)

CodexArcanum
  • 3,421
  • 21
  • 23
7

Autovivification (or other bind-variable-on-(assign|use) feature) is the feature which I've found to give me the most bugs.

Paul Nathan
  • 8,560
  • 1
  • 33
  • 41
7

PLEASE in INTERCAL. Don't use it enough, it complains. Use it too much, it complains.

Alan Pearce
  • 393
  • 4
  • 7
  • 2
    That language is not supposed to be used seriously. It was created to be a very 'unique' programming language, so it is full of things (e.g. comefrom - just on top of my mind) that don't make sense. – ShdNx Sep 24 '10 at 11:15
  • 4
    I thought that it would be obvious, but yes, I am aware that it's not a serious language. – Alan Pearce Sep 24 '10 at 12:07
  • 2
    Sorry, some people are too serious around here. – Mark C Oct 04 '10 at 14:15
  • 1
    Just discovered the language last week on Wikipedia and was blown away of how popular it was (and still ist O_O). – Oliver Weiler Nov 08 '10 at 22:36
  • There are a number of "challenge" languages and they are always popular, because coders tend to do the job because of a love of the chase. Also very popular for interview questions as they are deliberately obtuse, thought provoking and hard. – Orbling Nov 27 '10 at 01:21
6

In C/C++: That assignments are also expressions COMBINED WITH the very similar assignment = and comparison == operators. Not a harmful feature per se, but it's way to easy to introduce (sometimes subtle) bugs by accidentally mistyping the operator.

int i = 10;

someCode();

if(i = 5)
{
    /* We don't want this block to be executed, but it is */
    moreCode();
}
6

"Failing silently" in Flash Player as default behavior

Ok, not really a feature of the language itself but still pretty closely related.

Suddenly your Flash/Flex application stops working and nobody can give you the slightest hint what the f* has happened. No error message, no stacktrace, no nothing. It's just that suddenly the screen transition doesn't happen (or happens in a completely wrong way), or buttons don't react to clicks any longer, or comboboxes are empty instead of being populated with some entries.

That "feature" alone is responsible for several shrug reports and a whole bunch of gray hair I've been getting. -.- While popping up some cryptic message in the user's face isn't desirable either, it can at least help the developer getting the problem fixed.

But Flash Player leaves you stabbing around in the dark, relying on the user's description (while the problem may actually originate from a completely different location in the code that doesn't have anything to do with what the user was doing). Only if you use the Debug Player you actually get the popup window with an error message and a stacktrace.

However, it can be quite interesting to watch flash embedded movies on certain news sites and get repeated messages about Null references from the used embedded player SWF. :D

Baelnorn
  • 816
  • 5
  • 7
5

Replacing undefined variables by an empty string in shell without any warnings: rm -rf $nosuchvar/*.

duros
  • 2,464
  • 1
  • 21
  • 25
5

Access modifiers in Java with package private language default and private programming convention default.

Hoa Long Tam
  • 1,635
  • 10
  • 12
4

The ability to turn counterclockwise in LOGO. Wtf, lets just turn clockwise 360 - x degrees.

jjnguy
  • 509
  • 4
  • 7
  • Well, it's been a while since I used LOGO. Why is this harmful? – Mason Wheeler Oct 03 '10 at 20:05
  • 5
    Logo can be used to control a real, physical turtle robot. Sometimes you *want* the turtle to turn a specific direction, or to turn more than once. For example, maybe you’re programming it to do some kind of dance. – Daniel Cassidy Oct 03 '10 at 20:10
  • @Mason, It was supposed to be a joke. – jjnguy Oct 04 '10 at 03:01
  • @Dan, See above comment. – jjnguy Oct 04 '10 at 03:01
  • Fair enough! It did seem a bit of an odd complaint :P – Daniel Cassidy Oct 04 '10 at 13:41
  • 3
    Yeah, especially in LOGO For Clocks. – intuited Oct 19 '10 at 07:48
  • @int, I'm glad someone is getting the joke. – jjnguy Oct 19 '10 at 14:58
  • 1
    I love Logo (see http://programmers.stackexchange.com/questions/21028/which-language-did-you-love-from-heart/21063#21063) and it is an excellent teaching language, particularly for young people. When I was say 11 and first used Logo most of my class did not know that much geometry, but they got told 90 was a quarter turn and know left from right. So it isn't a negative feature - the same as why we don't multiply by reciprocals instead of having a divide operator. Yes, I know it's a joke. – Orbling Nov 27 '10 at 01:15
4

Stopping Thread from an other Thread

In Java and in other language you could stop a thread from an other one arbitrarily without giving the time for the thread you stopped to finish properly. This ability have been deprecated considering the huge amount of problem it could bring in nearly all situation.

HoLyVieR
  • 976
  • 1
  • 13
  • 16
  • While I suppose this *can* be harmful, there are times it's extremely useful (e.g., a debugger supporting single stepping and break points). – Jerry Coffin Sep 13 '10 at 18:59
  • 1
    @Jerry Debugging is an entire other thing, it doesn't stop the process, it pauses it. – HoLyVieR Sep 13 '10 at 23:01
  • rather the contrary, it stops the thread. Apparently, you're talking about *killing* the thread, not just stopping it though. That is a bit harder to justify... – Jerry Coffin Sep 13 '10 at 23:28
  • I don't see this as necessarily being a language feature though. More a standard library thing. – Jason Baker Nov 26 '10 at 23:46
4

Variable Variables in PHP

Just because you $can doesn't mean you $$should

Kendall Hopkins
  • 357
  • 2
  • 9
  • 1
    As usual, Perl... has the (potentially dangerous) feature available, has an easy best-practice way to turn it off (`use strict`) and an easy way to turn it on again in exactly the cases you'd want it (`no strict 'refs'`). –  Oct 02 '10 at 02:32
  • 1
    I have never found a use to have a dynamic variable name. And the only times I did, it made the code unreadable and a WTF moment a few months later when I revisited the code. – TheLQ Oct 03 '10 at 20:32
  • Mmm, applications include metaprogramming with other peoples' obnoxious package variables or the symbol table (which is a liittle different, I suppose). –  Oct 04 '10 at 05:21
  • this can be usefull... but most of the time is not. – WalterJ89 Oct 12 '10 at 20:33
  • Unless of course `$can == $$should`. – Joe D Oct 20 '10 at 17:09
  • 1
    @Joe I would challenge you to show me *one* example where variable variables make a solution clearer. – Kendall Hopkins Nov 03 '10 at 02:24
  • 1
    The comment *was* meant as a joke, sorry I didn't make that clear, but since you ask [here is the best example where variable variables make a solution clearer](http://stackoverflow.com/questions/1003605/when-to-use-a-variable-variable-in-php/1003638#1003638). I'll admit it's a rather bad example though. – Joe D Nov 03 '10 at 17:34
  • @Joe Oh, sorry, I thought it was literal, because it received a down vote for the answer. I guess someone else also didn't *get* the joke either :P – Kendall Hopkins Nov 03 '10 at 18:37
3

Arrays in AWK starting at index 1!

Oliver Weiler
  • 2,448
  • 19
  • 28
3

The With statement in Delphi comes to mind, although there are cases when it's usefull.

Remko
  • 111
  • 4
  • A good case when I ported something from Delphi to Lazarus and my TControl descendant contained "with Canvas do ... Width, Height" referencing the control sizes, but Lazarus TCanvas had its own Width and Delphi, so this led to wrongly compiled code – Maksee Jun 21 '12 at 09:55
2

Python 2.x's relative import syntax. Suppose I have a package x.plugins that adds support for various other libraries for x. And suppose I have a sqlalchemy module in x.plugins so I can add sqlalchemy support to x. What do you think will happen if I add the following line to sqlalchemy.py?

import sqlalchemy

The answer is that the module will try to import itself. What this syntax does is essentially make it impossible to import the actual global sqlalchemy package. Python 2.5 added a way to specify that this is a relative import:

from . import sqlalchemy

...but it isn't until Python 3 that the first syntax was actually gotten rid of (although it can be disabled in Python 2.6+ with from __future__ import absolute_import).

Jason Baker
  • 9,625
  • 8
  • 44
  • 67
2

In Perl, scalar context vs. list context can be tricky. It's got some good points that make certain operations convenient, but occasionally you run into something terrible, like completely changing the meaning of an operator (potentially from a significant distance away in the code).

sub foo { (1..5) }
my @list = foo();           # (1,2,3,4,5)
my $length = scalar @list;  # 5. the length of the list.
my $length2 = scalar foo(); # '' (the empty string. because it's false)

That's just not right.

(It arises from trying to make something that acts sort of like the regular range operator, so you can say something in a loop like next if /start_regex/ .. /end_regex/).

  • Man that is *so* confusing. The worst thing about learning Perl was trying to get my head around that. – glenatron Oct 12 '10 at 09:22
  • I always thought anything that allows a function to return in multiple ways was a handy convenience. – Orbling Nov 27 '10 at 01:22
1

magic_quotes in PHP.

Unexperienced developers either rely on it being enabled and thus assume all user input to be escaped for use in a SQL query or rely on it being disabled and thus always escape their input.

When assuming it's enabled and then running the code on a system where it's not it opens gaping wide SQL injection holes.

When assuming it's disabled and it's not, it will result in backslashes being actually stored in the DB, causing ugly/incorrect strings.

There is also no extremely simple way to handle both cases - you need to check if it's enabled using get_magic_quotes_gpc() and then apply stripslashes() on all values in the $_* arrays - since array_map is not recursive you need a custom function for this.

ThiefMaster
  • 1,325
  • 10
  • 16
1

Object Orientation (from all statically typed languages). I'll wager this feature has, and will continue, to cost vastly more than null pointers. Object Orientation is only good in a dynamic message passing language. So it should be dropped from dynamic languages like Python too (since it doesn't use message passing but conventional subroutine calling).

Yttrill
  • 727
  • 5
  • 10
  • Python supports (for all intents and purposes) smalltalk's message passing idiom. It just isn't named that way. Secondly, I think it's at least a little debatable to call such a pervasive language feature harmful. – Jason Baker Nov 26 '10 at 23:49
  • Object Orientation still improves code reuse and code/data encapsulation. Regardless of the static/dynamic uses of the feature. – Orbling Nov 27 '10 at 01:28
  • @Orbling: Compared to what? In my opinion functional programming languages have a higher code reuse and i think Haskell's module system is quite good for code/data encapsulation. – LennyProgrammers Dec 02 '10 at 11:52
  • @Lenny222 Compared to standard imperative programming. I too prefer the functional approach, Haskell is a preferred language of mine. – Orbling Dec 02 '10 at 12:02
  • @Jason Baker: well certainly it is debatable, but being so pervasive is precisely what makes it so harmful! The OP did ask for my opinion, and I gave it. Just because a bunch of Lemmings jump of a cliff doesn't make the behaviour sane. In this case it is mathematically proven OOP doesn't work, and the correct paradigm is well accepted: category theory is way to represent abstractions (it is in fact the theory of abstractions) – Yttrill Dec 04 '10 at 22:47
  • @Yttrill - I generally am highly skeptical of any theory that depends on most others being lemmings heading to a cliff. It usually indicates a very egocentric point of view. – Jason Baker Dec 05 '10 at 07:07
1

FORTRAN common blocks. If you made a simple mistake, one part of an application could clobber another part's globals.

FORTRAN assigned goto statement / COBOL alter statement. Self-modifying code. Danger, warning, flying spaghetti monsters!!

Stephen C
  • 25,180
  • 6
  • 64
  • 87
  • FORTRAN did not have an ALTER statement. FORTRAN had the ASSIGN statement, with the assigned GOTO. COBOL had the ALTER statement, which served a similar purpose. – John R. Strohm Oct 01 '10 at 18:56
  • @John - thanks. My memory of assign/alter is dim ... not least because I was taught to never use them. – Stephen C Oct 02 '10 at 00:01
1

sun.misc.unsafe is my alltime favorite; the collection of "we needed this to implement things, but really, really don't think you should use it."

Dean J
  • 908
  • 7
  • 11
  • 7
    Every good language **should** have an unsafe package in the standard library. Importing this package clearly shows your intent of doing low-level unportable things. The alternatives are: **1-** Having unsafe features in the language itself (C++ for example) and **2-** Having to use a different language such as C for doing low level things (Python and Ruby for example). The unsafe package approach seems much better to me. – imgx64 Sep 24 '10 at 05:28
-3

going out a bit on a limb here - void functions. a function always does something, hence it should either return the result or some other bit of information regarding its success or failure.

Brad Clawsie
  • 740
  • 3
  • 7
-3

The language feature that allows programmers to write uncommented or meaningless-commented code.

tia
  • 965
  • 5
  • 9
-4

POKE in BASIC...

squelart
  • 101
  • 1
-5

I'd have to say garbage collection. It does not eliminate the need to think about memory management, but it eliminates the perception of the need to think about memory management, which all too often eliminates the actual thought, and then you get enormous resource hogs and don't know why. Especially when the behavior of modern generational GCs could be described without too much hyperbole as "one big memory leak by design" anyway.

Mason Wheeler
  • 82,151
  • 24
  • 234
  • 309
  • This is simply not true. It is quite possible to write memory-efficient code with a garbage-collected language, and the GC eliminates a big chunk of programmer time (as opposed to program time). Garbage-collected languages have a lot of use-cases and it isn't useful to completely avoid using them. – Chinmay Kanchi Sep 10 '10 at 13:40
  • @Chinmay: Yes, it's "possible" to, but not common. Also, it only eliminates programmer time during initial development. When you've got references left sitting around in some collection somewhere and your memory footprint is way too big, and you've got no leak-tracing tools because you're using a garbage-collected language, you can lose *tons* of programmer time trying to track them down. – Mason Wheeler Sep 10 '10 at 14:25
  • 2
    If you've got references sitting around in some collection somewhere, you have other problems. – Chinmay Kanchi Sep 10 '10 at 15:03
  • So you say, but it's a surprisingly common problem. – Mason Wheeler Sep 11 '10 at 00:26
  • 2
    That's why gc'ed languages have weak references :) – Chinmay Kanchi Sep 11 '10 at 11:39
  • 4
    While GC certainly has both strengths and weaknesses, I'd have to say that Mason is a lot more right than wrong on this one. In fact, I've seen people using GC spend a lot of *extra* time on memory management because they ended up trying to hack things after the fact instead of planning for it up front. GC also generally prevents deterministic destruction, which leads to extra work dealing with managing all resources other than memory. – Jerry Coffin Sep 13 '10 at 19:21
  • 1
    If resource management is your problem I'd say imposing manual memory management is attacking the wrong problem. With manual memory management the malloc() efficiency and heap fragmentation can hurt a lot. Garbage collection makes new() fast and leaves cleaning up unused memory to a dedicated made-for-purpose background thread. While resource hogs, leaking references and heap littering still can cause problems, garbage collection still solves more problems than it causes. – Asgeir S. Nilsen Sep 14 '10 at 20:29
  • @Asegir: Not really. Heap fragmentation is only a problem if you're using a really primitive malloc implementation. Modern memory managers use buckets so the heap doesn't get fragmented. – Mason Wheeler Sep 14 '10 at 20:34
  • I can't believe after years of advancement in GC technology that people still think they are bad. Don't get me wrong, GC free languages have their place but you are a fool if you think they are the right tool for every job. – ChaosPandion Sep 14 '10 at 20:43
  • 3
    @ChaosPandion: Am I really a fool if I think that, on a modern multitasking machine, in order to keep paging from trashing your system performance, memory should be released as soon as possible? No GC has ever managed to even come close to achieving that result, and in fact, the generational garbage collector, which is supposed to be the best, most modern variety there is, does precisely the opposite: for best performance, it has to release memory as *late* as possible. I don't see that as ever the right tool for any job, not when it slows down my other programs. Am I a fool for that? – Mason Wheeler Sep 14 '10 at 20:53
  • @Mason - I am sorry if you read that as a direct personal attack. Quite frankly though I feel as if you don't have any idea about the improvements made in GC technology. If I can write a parser that contains zero mutable state and can parse massive source files and maintain under 15MB of memory usage I have to say that the GC is doing a really good job. OK, so maybe you could write one in C that uses 8MB at most... Who cares....? – ChaosPandion Sep 14 '10 at 21:07
  • @ChaosPandion: OK, fair enough, if all you're doing is parsing source files and using memory in the low double-digits of MB it probably doesn't matter all that much. I tend to inhabit different problem domains, though. At work I maintain a massive enterprise-level inventory and control system for broadcast media. (If you watch TV or listen to the radio in the USA, the station's probably running on software I worked on.) And in my spare time, I like to both play and hack around in video games. In those worlds, the scale of your memory consumption really matters. That's where I'm coming from. – Mason Wheeler Sep 14 '10 at 21:17
  • @Mason - Like I said, the right tool for the job. *(One again, I am sorry for the poor wording in my original comment.)* – ChaosPandion Sep 14 '10 at 21:25
  • @ChaosPandion: All right. Apology accepted. – Mason Wheeler Sep 14 '10 at 21:28
  • @Mason We've been bitten by this on Solaris 10 and Sun Studio 11, so it can still hurt. That being said -- the bits of memory we were allocating / freeing were gigabyte-sized, something the memory manager probably wasn't designed to handle. – Asgeir S. Nilsen Sep 16 '10 at 17:18
  • A malloc library that uses heaps and buckets is just one step away from a generational garbage collector. It's already managing the pool for you and trying to be intelligent about allocating/deallocating resources. A call to free() almost certainly doesn't release it back to the OS; it just goes back in the pool. Because of the pool management, I think it would be difficult to say that calls to malloc() and free() have deterministic performance. – Barry Brown Oct 03 '10 at 21:16
  • 2
    @Barry: It's deterministic within the program. If I'm done with a 5 KB block of memory, then ask for another 5 KB soon afterwards, what happens? In a garbage collected system, it needs to request a new 5 KB block, even though there's a perfectly good block sitting unused, unless the GC has run in the interim, in which case you can recycle the old block. With malloc and free, you'll always be able to recycle the old block. Multiply this by a few hundred thousand and it becomes a real issue. – Mason Wheeler Oct 03 '10 at 22:03
  • People who don't think about memory management will (not) do that regardless of whether they have a garbage collector or not. I've seen a lot of leaky Delphi code. GC's protect bad programmers from themselves (partly), and don't get in the way of good programmers (who end up writing identical code anyway, cleaning up stuff right after they use it). – Joeri Sebrechts Oct 12 '10 at 17:52
  • 1
    @Joeri: **Should bad programmers be protected?** I realise that's another question, but really - this whole question here revolves around the need to shield computers from poor coders. I say leave the power and the risk and let the poorer coders get fired making the profession stronger. – Orbling Nov 27 '10 at 01:41
  • @Orbling: Should cars have ABS, power steering and navigation systems? To me compilers and IDE's are just programs with their own set of end-users. There's no such thing as a programmer, there are only degrees of sophistication in users. Software should be user-friendly. Not including useful features because they only are necessary for "noobs" is elitist, and imho a sign of bad craftsmanship. – Joeri Sebrechts Nov 28 '10 at 11:49
  • 2
    @Joeri You are welcome to your opinion, I however firmly believe in elitism in professions. There are definitely programmers, as there are doctors and pilots. You would not want a non-professional performing heart surgery on you, and I for one do not like e-commerce websites for instance being built by non-experts; it is dangerous - there should be compulsory certification. On your driving example, I have always said driving should be a profession and restricted to experts - the road fatality rates as the leading cause of death in young adults attest to that. – Orbling Nov 28 '10 at 12:03
  • I agree that for some classes of software we need mechanisms of certification to ensure the software is built the right way, like we require mandatory safety testing for cars. However, we were talking about removing garbage collecting from all programming languages, and I don't think that helps you get one step closer to better software. On the contrary, you'd just get the same people building software that doesn't clean up after itself and is less reliable as a result. The problem is not technical, it's sociological. It cannot be solved through technology. – Joeri Sebrechts Dec 03 '10 at 07:27
-5

C, and definitely C++: Pointer arithmetic. Allowing people to convert integers into memory addresses is asking for trouble.

And maybe even raw access to pointers altogether?

In C++ you have references that makes pointers almost completely unnecessary. For the remaining cases smart pointers should be considered mandatory.

Java is also proves that you can make a programming language that uses pointers without allowing people access to the pointer value itself.

Apart from null ... but that's a different story.

  • 5
    Pointers, while difficult to use properly at times, are very necessary for a great number of efficient memory operations. – Bill Sep 13 '10 at 21:27
  • 1
    True. But allowing people to convert integers into memory references on a regular basis, or adding numbers to memory addresses is mostly harmful these days in my opinion. In C++ you have references as a perfectly good alternative, and smart pointers / auto pointers for when you really need it to be a pointer. – Asgeir S. Nilsen Sep 14 '10 at 20:15
  • 4
    This answer is *only* valid if you are working on a software stack constructed to hide pointers. In *all* other cases, this answer is wrong. – Paul Nathan Sep 14 '10 at 21:07
  • 3
    *Some* programming language needs to have pointers available so you can write all the operating systems and virtual machines for the other programming languages. –  Oct 02 '10 at 02:35
  • 2
    -1. There is a reason you need ptr arithmetic: Iterating a point is fast than indexing. `for(int i=0;i – KitsuneYMG Oct 02 '10 at 02:43
  • fennec: For accessing hardware -- true, you need to be able to deal with specific address values. – Asgeir S. Nilsen Oct 04 '10 at 08:08
  • kts: The former is much more readable than the latter, and if the latter is faster I'd blame that on the CPU or the compiler, not the language feature. `sun.misc.Unsafe` is _not_ part of the Java language or the Java standard library. It's an internal Sun JVM implementation class not meant for public consumption. As for the need of a swap it's not something I miss on a regular basis. – Asgeir S. Nilsen Oct 04 '10 at 08:12
  • If you had said allowing integer type variables to be used for pointer arithmetic uncast to a pointer type, then yes, I'd agree - half the problems with getting code converted to x64 are down to pointer type issues. Pointer arithmetic itself is a necessary and useful feature, but dangerous, power is dangerous. – Orbling Nov 27 '10 at 01:35