{
    "mode": "perldoc",
    "parameter": "common::sense",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/common%3A%3Asense/json",
    "generated": "2026-06-10T23:35:25Z",
    "synopsis": "use common::sense;\n# Supposed to be mostly the same, with much lower memory usage, as:\n# use utf8;\n# use strict qw(vars subs);\n# use feature qw(say state switch);\n# use feature qw(unicodestrings unicodeeval currentsub fc evalbytes);\n# no feature qw(arraybase);\n# no warnings;\n# use warnings qw(FATAL closed threads internal debugging pack\n#                 prototype inplace io pipe unpack malloc glob\n#                 digit printf layer reserved taint closure semicolon);\n# no warnings qw(exec newline unopened);",
    "sections": {
        "NAME": {
            "content": "common::sense - save a tree AND a kitten, use common::sense!\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use common::sense;\n\n# Supposed to be mostly the same, with much lower memory usage, as:\n\n# use utf8;\n# use strict qw(vars subs);\n# use feature qw(say state switch);\n# use feature qw(unicodestrings unicodeeval currentsub fc evalbytes);\n# no feature qw(arraybase);\n# no warnings;\n# use warnings qw(FATAL closed threads internal debugging pack\n#                 prototype inplace io pipe unpack malloc glob\n#                 digit printf layer reserved taint closure semicolon);\n# no warnings qw(exec newline unopened);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "“Nothing is more fairly distributed than common sense: no one thinks\nhe needs more of it than he already has.”\n\n– René Descartes\n\nThis module implements some sane defaults for Perl programs, as defined by two typical (or not\nso typical - use your common sense) specimens of Perl coders. In fact, after working out details\non which warnings and strict modes to enable and make fatal, we found that we (and our code\nwritten so far, and others) fully agree on every option, even though we never used warnings\nbefore, so it seems this module indeed reflects a \"common\" sense among some long-time Perl\ncoders.\n\nThe basic philosophy behind the choices made in common::sense can be summarised as: \"enforcing\nstrict policies to catch as many bugs as possible, while at the same time, not limiting the\nexpressive power available to the programmer\".\n\nTwo typical examples of how this philosophy is applied in practise is the handling of\nuninitialised and malloc warnings:\n\n*uninitialised*\n\"undef\" is a well-defined feature of perl, and enabling warnings for using it rarely catches\nany bugs, but considerably limits you in what you can do, so uninitialised warnings are\ndisabled.\n\n*malloc*\nFreeing something twice on the C level is a serious bug, usually causing memory corruption.\nIt often leads to side effects much later in the program and there are no advantages to not\nreporting this, so malloc warnings are fatal by default.\n\nUnfortunately, there is no fine-grained warning control in perl, so often whole groups of useful\nwarnings had to be excluded because of a single useless warning (for example, perl puts an\narbitrary limit on the length of text you can match with some regexes before emitting a warning,\nmaking the whole \"regexp\" category useless).\n\nWhat follows is a more thorough discussion of what this module does, and why it does it, and\nwhat the advantages (and disadvantages) of this approach are.\n",
            "subsections": []
        },
        "RATIONALE": {
            "content": "use utf8\nWhile it's not common sense to write your programs in UTF-8, it's quickly becoming the most\ncommon encoding, is the designated future default encoding for perl sources, and the most\nconvenient encoding available (you can do really nice quoting tricks...). Experience has\nshown that our programs were either all pure ascii or utf-8, both of which will stay the\nsame.\n\nThere are few drawbacks to enabling UTF-8 source code by default (mainly some speed hits due\nto bugs in older versions of perl), so this module enables UTF-8 source code encoding by\ndefault.\n\nuse strict qw(subs vars)\nUsing \"use strict\" is definitely common sense, but \"use strict 'refs'\" definitely overshoots\nits usefulness. After almost two decades of Perl hacking, we decided that it does more harm\nthan being useful. Specifically, constructs like these:\n\n@{ $var->[0] }\n\nMust be written like this (or similarly), when \"use strict 'refs'\" is in scope, and $var can\nlegally be \"undef\":\n\n@{ $var->[0] || [] }\n\nThis is annoying, and doesn't shield against obvious mistakes such as using \"\", so one would\neven have to write (at least for the time being):\n\n@{ defined $var->[0] ? $var->[0] : [] }\n\n... which nobody with a bit of common sense would consider writing: clear code is clearly\nsomething else.\n\nCuriously enough, sometimes perl is not so strict, as this works even with \"use strict\" in\nscope:\n\nfor (@{ $var->[0] }) { ...\n\nIf that isn't hypocrisy! And all that from a mere program!\n\nuse feature qw(say state given ...)\nWe found it annoying that we always have to enable extra features. If something breaks\nbecause it didn't anticipate future changes, so be it. 5.10 broke almost all our XS modules\nand nobody cared either (or at least I know of nobody who really complained about gratuitous\nchanges - as opposed to bugs).\n\nFew modules that are not actively maintained work with newer versions of Perl, regardless of\nuse feature or not, so a new major perl release means changes to many modules - new keywords\nare just the tip of the iceberg.\n\nIf your code isn't alive, it's dead, Jim - be an active maintainer.\n\nBut nobody forces you to use those extra features in modules meant for older versions of\nperl - common::sense of course works there as well. There is also an important other mode\nwhere having additional features by default is useful: commandline hacks and internal use\nscripts: See \"much reduced typing\", below.\n\nThere is one notable exception: \"unicodeeval\" is not enabled by default. In our opinion,\n\"use feature\" had one main effect - newer perl versions don't value backwards compatibility\nand the ability to write modules for multiple perl versions much, after all, you can use\nfeature.\n\n\"unicodeeval\" doesn't add a new feature, it breaks an existing function.\n\nno warnings, but a lot of new errors\nAh, the dreaded warnings. Even worse, the horribly dreaded \"-w\" switch: Even though we don't\ncare if other people use warnings (and certainly there are useful ones), a lot of warnings\nsimply go against the spirit of Perl.\n\nMost prominently, the warnings related to \"undef\". There is nothing wrong with \"undef\": it\nhas well-defined semantics, it is useful, and spitting out warnings you never asked for is\njust evil.\n\nThe result was that every one of our modules did \"no warnings\" in the past, to avoid\nsomebody accidentally using and forcing his bad standards on our code. Of course, this\nswitched off all warnings, even the useful ones. Not a good situation. Really, the \"-w\"\nswitch should only enable warnings for the main program only.\n\nFunnily enough, perllexwarn explicitly mentions \"-w\" (and not in a favourable way, calling\nit outright \"wrong\"), but standard utilities, such as prove, or MakeMaker when running \"make\ntest\", still enable them blindly.\n\nFor version 2 of common::sense, we finally sat down a few hours and went through *every\nsingle warning message*, identifying - according to common sense - all the useful ones.\n\nThis resulted in the rather impressive list in the SYNOPSIS. When we weren't sure, we didn't\ninclude the warning, so the list might grow in the future (we might have made a mistake,\ntoo, so the list might shrink as well).\n\nNote the presence of \"FATAL\" in the list: we do not think that the conditions caught by\nthese warnings are worthy of a warning, we *insist* that they are worthy of *stopping* your\nprogram, *instantly*. They are *bugs*!\n\nTherefore we consider \"common::sense\" to be much stricter than \"use warnings\", which is good\nif you are into strict things (we are not, actually, but these things tend to be\nsubjective).\n\nAfter deciding on the list, we ran the module against all of our code that uses\n\"common::sense\" (that is almost all of our code), and found only one occurrence where one of\nthem caused a problem: one of elmex's (unreleased) modules contained:\n\n$fmt =~ s/([^\\s\\[]*)\\[( [^\\]]* )\\]/\\x0$1\\x1$2\\x0/xgo;\n\nWe quickly agreed that indeed the code should be changed, even though it happened to do the\nright thing when the warning was switched off.\n\nmuch reduced typing\nEspecially with version 2.0 of common::sense, the amount of boilerplate code you need to add\nto get *this* policy is daunting. Nobody would write this out in throwaway scripts,\ncommandline hacks or in quick internal-use scripts.\n\nBy using common::sense you get a defined set of policies (ours, but maybe yours, too, if you\naccept them), and they are easy to apply to your scripts: typing \"use common::sense;\" is\neven shorter than \"use warnings; use strict; use feature ...\".\n\nAnd you can immediately use the features of your installed perl, which is more difficult in\ncode you release, but not usually an issue for internal-use code (downgrades of your\nproduction perl should be rare, right?).\n\nmucho reduced memory usage\nJust using all those pragmas mentioned in the SYNOPSIS together wastes <blink>*776\nkilobytes*</blink> of precious memory in my perl, for *every single perl process using our\ncode*, which on our machines, is a lot. In comparison, this module only uses *four*\nkilobytes (I even had to write it out so it looks like more) of memory on the same platform.\n\nThe money/time/effort/electricity invested in these gigabytes (probably petabytes globally!)\nof wasted memory could easily save 42 trees, and a kitten!\n\nUnfortunately, until everybody applies more common sense, there will still often be modules\nthat pull in the monster pragmas. But one can hope...\n\nTHERE IS NO 'no common::sense'!!!! !!!! !!\nThis module doesn't offer an unimport. First of all, it wastes even more memory, second, and\nmore importantly, who with even a bit of common sense would want no common sense?\n",
            "subsections": []
        },
        "STABILITY AND FUTURE VERSIONS": {
            "content": "Future versions might change just about everything in this module. We might test our modules and\nupload new ones working with newer versions of this module, and leave you standing in the rain\nbecause we didn't tell you. In fact, we did so when switching from 1.0 to 2.0, which enabled\ngobs of warnings, and made them FATAL on top.\n\nMaybe we will load some nifty modules that try to emulate \"say\" or so with perls older than 5.10\n(this module, of course, should work with older perl versions - supporting 5.8 for example is\njust common sense at this time. Maybe not in the future, but of course you can trust our common\nsense to be consistent with, uhm, our opinion).\n",
            "subsections": []
        },
        "WHAT OTHER PEOPLE HAD TO SAY ABOUT THIS MODULE": {
            "content": "apeiron\n\n\"... wow\"\n\"I hope common::sense is a joke.\"\n\ncrab\n\n\"i wonder how it would be if joerg schilling wrote perl modules.\"\n\nAdam Kennedy\n\n\"Very interesting, efficient, and potentially something I'd use all the time.\"\n[...]\n\"So no common::sense for me, alas.\"\n\nH.Merijn Brand\n\n\"Just one more reason to drop JSON::XS from my distribution list\"\n\nPista Palo\n\n\"Something in short supply these days...\"\n\nSteffen Schwigon\n\n\"This module is quite for sure *not* just a repetition of all the other\n'use strict, use warnings'-approaches, and it's also not the opposite.\n[...] And for its chosen middle-way it's also not the worst name ever.\nAnd everything is documented.\"\n\nBKB\n\n\"[Deleted - thanks to Steffen Schwigon for pointing out this review was\nin error.]\"\n\nSomni\n\n\"the arrogance of the guy\"\n\"I swear he tacked somenoe else's name onto the module\njust so he could use the royal 'we' in the documentation\"\n\nAnonymous Monk\n\n\"You just gotta love this thing, its got META.json!!!\"\n\ndngor\n\n\"Heh.  '\"<elmex at ta-sa.org>\"'  The quotes are semantic\ndistancing from that e-mail address.\"\n\nJerad Pierce\n\n\"Awful name (not a proper pragma), and the SYNOPSIS doesn't tell you\nanything either. Nor is it clear what features have to do with \"common\nsense\" or discipline.\"\n\nacme\n\n\"THERE IS NO 'no common::sense'!!!! !!!! !!\"\n\napeiron (meta-comment about us commenting^Wquoting his comment)\n\n\"How about quoting this: get a clue, you fucktarded amoeba.\"\n\nquanth\n\n\"common sense is beautiful, json::xs is fast, Anyevent, EV are fast and\nfurious. I love mlehmannware ;)\"\n\napeiron\n\n\"... it's mlehmann's view of what common sense is. His view of common\nsense is certainly uncommon, insofar as anyone with a clue disagrees\nwith him.\"\n\napeiron (another meta-comment)\n\n\"apeiron wonders if his little informant is here to steal more quotes\"\n\new73\n\n\"... I never got past the SYNOPSIS before calling it shit.\"\n[...]\nHow come no one ever quotes me. :(\"\n\nchip (not willing to explain his cryptic questions about links in Changes files)\n\n\"I'm willing to ask the question I've asked. I'm not willing to go\nthrough the whole dance you apparently have choreographed. Either\nanswer the completely obvious question, or tell me to fuck off again.\"\n",
            "subsections": []
        },
        "FREQUENTLY ASKED QUESTIONS": {
            "content": "Or frequently-come-up confusions.\n\nIs this module meant to be serious?\nYes, we would have put it under the \"Acme::\" namespace otherwise.\n\nBut the manpage is written in a funny/stupid/... way?\nThis was meant to make it clear that our common sense is a subjective thing and other people\ncan use their own notions, taking the steam out of anybody who might be offended (as some\npeople are always offended no matter what you do).\n\nThis was a failure.\n\nBut we hope the manpage still is somewhat entertaining even though it explains boring\nrationale.\n\nWhy do you impose your conventions on my code?\nFor some reason people keep thinking that \"common::sense\" imposes process-wide limits, even\nthough the SYNOPSIS makes it clear that it works like other similar modules - i.e. only\nwithin the scope that \"use\"s them.\n\nSo, no, we don't - nobody is forced to use this module, and using a module that relies on\ncommon::sense does not impose anything on you.\n\nWhy do you think only your notion of common::sense is valid?\nWell, we don't, and have clearly written this in the documentation to every single release.\nWe were just faster than anybody else w.r.t. to grabbing the namespace.\n\nBut everybody knows that you have to use strict and use warnings, why do you disable them?\nWell, we don't do this either - we selectively disagree with the usefulness of some warnings\nover others. This module is aimed at experienced Perl programmers, not people migrating from\nother languages who might be surprised about stuff such as \"undef\". On the other hand, this\ndoes not exclude the usefulness of this module for total newbies, due to its strictness in\nenforcing policy, while at the same time not limiting the expressive power of perl.\n\nThis module is considerably *more* strict than the canonical \"use strict; use warnings\", as\nit makes all its warnings fatal in nature, so you can not get away with as many things as\nwith the canonical approach.\n\nThis was not implemented in version 1.0 because of the daunting number of warning categories\nand the difficulty in getting exactly the set of warnings you wish (i.e. look at the\nSYNOPSIS in how complicated it is to get a specific set of warnings - it is not reasonable\nto put this into every module, the maintenance effort would be enormous).\n\nBut many modules \"use strict\" or \"use warnings\", so the memory savings do not apply?\nI suddenly feel sad...\n\nBut yes, that's true. Fortunately \"common::sense\" still uses only a miniscule amount of RAM.\n\nBut it adds another dependency to your modules!\nIt's a fact, yeah. But it's trivial to install, most popular modules have many more\ndependencies. And we consider dependencies a good thing - it leads to better APIs, more\nthought about interworking of modules and so on.\n\nWhy do you use JSON and not YAML for your META.yml?\nThis is not true - YAML supports a large subset of JSON, and this subset is what META.yml is\nwritten in, so it would be correct to say \"the META.yml is written in a common subset of\nYAML and JSON\".\n\nThe META.yml follows the YAML, JSON and META.yml specifications, and is correctly parsed by\nCPAN, so if you have trouble with it, the problem is likely on your side.\n\nBut! But!\nYeah, we know.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Marc Lehmann <schmorp@schmorp.de>\nhttp://home.schmorp.de/\n\nRobin Redeker, \"<elmex at ta-sa.org>\".\n",
            "subsections": []
        }
    },
    "summary": "common::sense - save a tree AND a kitten, use common::sense!",
    "flags": [],
    "examples": [],
    "see_also": []
}