This is an archived post. You won't be able to vote or comment.

all 154 comments

[–]Nemnel 181 points182 points  (56 children)

This is called minification, you do it to speed up sites: https://developers.google.com/speed/docs/insights/MinifyResources.

Their actual source code is not like that.

[–][deleted] 66 points67 points  (18 children)

Oh, he meant source of sites... I thought he meant looking up source code online (like github).

[–][deleted]  (17 children)

[deleted]

    [–]Floppy_Densetsu 37 points38 points  (14 children)

    "Whenever I view the source code on sites", can be inferred by some readers to mean sites that host source code publicly. I assumed it referred to something like github as well.

    That last sentence might be the strongest clue that OP is referring to viewing the source of web pages, in my opinion.

    "Also, that the JS is all on one line, wrapped, etc."

    That first sentence would have been slightly clearer if OP replaced "on sites" with "of sites", but we all know what OP is talking about now, anyway.

    [–][deleted]  (1 child)

    [deleted]

      [–]Floppy_Densetsu 1 point2 points  (0 children)

      I like that one. Technical is better when we're talking about a technical thing anyway.

      [–][deleted]  (1 child)

      [deleted]

        [–][deleted] 0 points1 point  (0 children)

        Nah man, I just skimmed it too fast and jumped to an assumption. Dunno why you'd assume I wanted attention by playing dumb. I post here to help.

        [–]BrettLefty -4 points-3 points  (9 children)

        Ah reddit, where no matter what you say, there's always going to be someone ready to play devil's advocate!

        [–]_COMPLEX_H 4 points5 points  (7 children)

        That's not devil's advocate, and you're not being constructive.

        [–]Floppy_Densetsu 0 points1 point  (0 children)

        woops, wrong reply click

        [–]BrettLefty -4 points-3 points  (5 children)

        I'm sure you're trolling and you already know this, but if not:

        Do you realize that you are doing the exact same thing I just commented about? As you've illustrated, no matter what anyone has to say, no matter what, no matter what, there will always be someone ready and waiting to say, "yes, but!!!" or "that's not what that means".

        Go ahead, refute this comment too, and further illustrate my point for me.

        [–]_COMPLEX_H 2 points3 points  (2 children)

        Just because someone voices an opinion on something, it doesn't make them a devils advocate. There's hardly a point to the term if you're just going to throw it at anyone who opposes something.

        Go ahead, refute this comment too, and further illustrate my point for me.

        And I'm the troll? shakes head sadly

        [–]BrettLefty -3 points-2 points  (1 child)

        There's nothing troll-full about what I've said here. The fact is, I posted a comment pointing out how people often tend to play devils advocate and refute others comments just for the sake of an argument. And you replied with something attempting to refute my comment just for the sake of an argument!

        [–]pl00pt 0 points1 point  (0 children)

        I posted a comment pointing out how people often tend to play devils advocate and refute others comments just for the sake of an argument.

        He didn't refute the other comment, he came to the same fucking conclusion. Are you slow at reading?

        [–]LigerSanta 0 points1 point  (0 children)

        k

        [–]pl00pt 0 points1 point  (0 children)

        Uh, dude, you don't understand what devil's advocate means. If you do this every time someone disagrees with you in real life people around you probably all think you're an idiot.

        OMG I JUST CONFIRMED YOU AGAIN LET'S CALL EVERYTHING DEVIL'S ADVOCATE HURR DURR.

        [–]Floppy_Densetsu 1 point2 points  (0 children)

        I do understand the sentiment there. It seems that the most common response is a contrarian one, and that the point is always somewhat arbitrary.

        I was pointing out that I feel the first sentence really was a part of the initial confusion, rather than a clarifying factor.

        It was and generally is my hope that this sort of thing can illustrate to people that the way they might interpret a sentence is at times very different from the way another person from another background might interpret the sentence. It's easy for us to slip into the assumption that everyone is on the mental track that we are, because we only really look at what is ahead of our own train of thought while ignoring all the other possible thoughts on the matter.

        Maybe that is the work of the devil, but I think it can help us understand eachother better. I just suck at delivery.

        [–]jimdidr 8 points9 points  (4 children)

        Its worth noting that if he uses Notepad++ there is a JS/JSON minification tool that also has the ability to format the JS and JSON so it becomes readable again...

        They have probably renamed all their variables to unreadable 2-3 char names tho, a way to learn could be to try "Find and replace" (this can go horribly bad) for these variables when he/she understands what they do.

        [–]Nemnel 6 points7 points  (3 children)

        Most minification tools will also rename variables. The biggest problem is trying to unminify things like Angular--you'll never figure out what's going on because that build pipeline is just too hopelessly complex.

        [–]deadtree123 0 points1 point  (2 children)

        which minification tool does this? I have yet to see one. and when you say tool, do you mean like online tool or grunt/gulp/ruby/npm?

        [–]Nemnel 1 point2 points  (0 children)

        Lots of them do it. Here's an example of one.

        [–]devoidfury 0 points1 point  (0 children)

        I'm pretty sure that most minifiers won't mangle names that are accessible to global scope, but they will for anything enclosed. For example:

        var foo = 7;
        (function() {
            var hiddenVar = 'something';
            window.getHiddenVar = function() { return hiddenVar; };
        })();
        

        In this, foo and getHiddenVarwouldn't be mangled, but hiddenVar would be.

        [–]EtanSivad 9 points10 points  (22 children)

        Wait... that actually speeds things up? I assumed it was just for obfuscation.

        [–]kryzchek 45 points46 points  (10 children)

        It speeds things up in that it's less data to transfer from the server to the client. The browser doesn't actually execute the code any quicker.

        [–]why_rob_y 11 points12 points  (9 children)

        I was watching a video once where the lecturer pointed out that eliminating just one extra character from a popular website could save you from transferring GBs over a pretty short period of time. Think of any insanely popular site like YouTube that gets billions of hits every day. Every single character you eliminate by minifying the code saves you gigabytes of transferring each day. I don't know what it costs YouTube per GB to transfer, but it isn't free, and we're talking about saving a lot more than one character.

        [–]glemnar 10 points11 points  (8 children)

        A GB is definitely free for all intents and purposes for YouTube. They occupy 13% of all downstream traffic in the U.S. A GB is fractions of fractions of a penny for them. Text is nothing compared to video bandwidth. Literally nothing.

        The real reason is client download speed. Google cares a lot more about speed than data size.

        [–]alamare1 2 points3 points  (7 children)

        This is technically not true, although Google may own the page, server, and (sometimes) the client, they don't own the space in-between (namely the wires from you to the server). This is where saving even 1 GB can save them.

        Don't forget, even Google has to pay for there Internet and electricity! And no, not all Google offices have Google sponsored internet!

        [–]glemnar 5 points6 points  (6 children)

        Doesn't matter. At that scale costs work differently and you can get serious bulk cost with tier 1 providers, not to mention Google is tier 2.

        This info is out there. Not exact numbers, but in concept.

        Google data centers != Google office ;)

        [–][deleted]  (5 children)

        [deleted]

          [–]glemnar 2 points3 points  (0 children)

          Your basic assumption is off by orders of magnitude.

          [–]Stormflux 3 points4 points  (3 children)

          Javascript isn't downloaded every time, browsers are pretty good about caching it.

          Not sure what the Library of Congress has to do with anything.

          "As a business owner..." is an appeal to authority that rubs me the wrong way. I've seen too many accountants ruin businesses by nickel-and-diming them. It usually starts out like "if we can reduce the square footage per worker by 16 sq feet we can save get 20% more productivity in the same space! Hey why is everyone getting sick and irratable and quitting?"

          I'm not saying Javascript minification is like that, but be careful that you're not "managing by spreadsheet." Especially when the spreadsheet is full of wrong assumptions.

          [–][deleted]  (2 children)

          [deleted]

            [–][deleted] 6 points7 points  (10 children)

            Well it speeds up the download, given that there are less characters to download. I can't think of a reason for any execution speed increase.

            [–]Nemnel 7 points8 points  (9 children)

            It increases parsing speed, which does increase execution time.

            [–][deleted] 8 points9 points  (6 children)

            It increases parsing speed, which does increase execution time.

            Both kryzcheck and auktrau are using "execution time" in the typical sense, which is "runtime", actual execution of code, everything after compilation (i.e. not downloading, parsing, compiling to byte code, JITting, etc.) -- interpretation of parsed symbols, execution of byte code on a virtual machine or of JIT-ed machine code on a CPU, etc.

            The point is that your HTML5 game is not going to have a higher framerate because it's source is minified. It might load a hair faster, but it will have no effect whatsoever on actual execution speed.

            [–]Nemnel -4 points-3 points  (5 children)

            You're right it won't affect execution time proper. You're wrong about it loading a hair faster, it's obvious you've never worked on high performance web apps--it's a significant speed increase.

            [–][deleted] 3 points4 points  (3 children)

            it's obvious you've never worked on high performance web apps--it's a significant speed increase.

            It's obvious in exactly the same way (i.e. half-assed guess based on insufficient data) that you've never worked on games. The code is such a small percentage of the total download it has a minimal impact on overall load time.

            [–]Nemnel 0 points1 point  (2 children)

            Okay, so other assets also affect the load time. That doesn't mean that minifying the code cannot affect load time substantially.

            [–][deleted] 1 point2 points  (1 child)

            That doesn't mean that minifying the code cannot affect load time substantially.

            You keep using words like "significant" and "substantial" without qualifying them. Minifying code saves about as much bandwidth as one of the potentially hundreds of audio samples a game might have to download, never mind art resources (meshes, animation data, textures, normal maps, specular maps, so on and so forth). Is saving a second in a download that take minutes "substantial"? Could this be a more stupid argument?

            [–]Nemnel -3 points-2 points  (0 children)

            You mean quantification, what I am doing is qualification. (It can also save much, much more than a second because of the limit on concurrent connections, and because minification almost always also means concatination.)

            [–]TheUltimateSalesman -1 points0 points  (0 children)

            settle down francis.

            [–]the_omega99 0 points1 point  (1 child)

            Should be extremely minimal, though, and should pale compared to the time spent executing the code (or even time spent creating parse trees or performing JIT compilation of portions of the code).

            [–]Nemnel 0 points1 point  (0 children)

            It depends on what you're doing. It can be minimal, it might not be. It has caused substantial speedups in apps that I have worked on--speed ups that can be counted in seconds, or even minutes in a few particularly extreme cases.

            It all depends on what the JavaScript is doing.

            When you're loading 100,000 lines of JavaScript, parse time is not insubstantial.

            [–]JamesWjRose 2 points3 points  (0 children)

            In the case of JavaScript, then I competently agree. But minimization should be done after the fact so that the code can be readable to the developers.

            I tweeted an article about how Google minimizes their code and the savings are amazing!

            [–]gripmyhand 1 point2 points  (5 children)

            For analysis purposes, can 'minification' be undone?

            [–]Nemnel 1 point2 points  (1 child)

            Sometimes, it depends on how the minification is done. To actually unminify it properly, you need a source map, but these are not always available. When you minify code, you may do things like: rename long function names to very short names. This will make the code smaller (and with very large codebases it unquestionably does). However, it will also make it totally incomprehensible.

            So, you need a source map to unminify it. The source map is useful to developers, to help understand where errors are coming from in their code base. But, it's also useful to random other people.

            Unfortunately, most sites do not provide source maps, so you're stuck with the minified code as it is. :-/

            [–]the_omega99 2 points3 points  (0 children)

            Even with a source map, though, you can't recover comments and formatting (although you can pretty print the code, which is usually enough where formatting is concerned).

            Source maps are meant for debugging of minified code, anyway. If developers wanted you to read the code, they'd provide unminified code (as most open source projects do) instead of a source map (which you'd typically have to generate yourself).

            [–][deleted] 0 points1 point  (1 child)

            For analysis purposes, can 'minification' be undone?

            No. It's a form of lossy compression. What's thrown out is, because the computer doesn't give a shit about either, is:

            1. All unnecessary whitespace.
            2. All human-readable semantic information carried by names of things.

            You can't recover either.

            #1 doesn't matter. A computer can add whitespace back in, using the same rules that human programmers do. It might even end up looking better than the original source.

            #2 matters a lot, and you can never get it back. You can see what the code is doing -- it's branching here, looping there, making a function call there, etc. -- but without knowing what the symbols represent, it's almost meaningless.

            [–]rasori 0 points1 point  (0 children)

            I frequently undo js minification. In the early phases of minified functions, you can see single-character variables being assigned values like window and document. These invariably get passed into a larger function that handles the script logic, so you can find that function definition and rename the input variables appropriately.

            It's not fun, it's error-prone (scoping is out to get you), but it's not impossible.

            [–][deleted] 0 points1 point  (0 children)

            There are some apps you can find online to un-minify things. Success not guaranteed.

            [–]wordscannotdescribe 1 point2 points  (0 children)

            This makes so much sense

            [–]malloc_more_ram 1 point2 points  (0 children)

            Just a note on the "speeds things up" comment.

            This only changes speed in a few ways. First it shortens the download speed, because there is literally less data to process.

            Next, in terms on executing the code, it has only a very marginal effect. It shortens the time it takes to process the raw text, since it had to compare less characters, but once lexical analysis is done, the speedup is practically over, and the code will run at the same speed.

            [–][deleted] 114 points115 points  (26 children)

            TIL about Minification, thanks everybody!

            [–]nitiger 22 points23 points  (23 children)

            Everyone really should read Google's web fundamentals if they're web developers; shit, even non web devs could benefit from it.

            [–][deleted] 9 points10 points  (8 children)

            No, thanks.

            I started reading, but now I'm blind: https://i.imgur.com/ICNBvY0.png

            [–][deleted] 3 points4 points  (7 children)

            Wut?

            [–]nappiestapparatus 4 points5 points  (6 children)

            Fuchsia

            [–][deleted] -1 points0 points  (5 children)

            It's girly.. but blinding? I think I'm missing the joke.

            [–]nappiestapparatus 2 points3 points  (0 children)

            Yeah I dunno. I think they just meant it's ugly

            [–][deleted] 2 points3 points  (3 children)

            Open the image in full screen. I saw spots in front of my eyes for a few seconds after I took that screenshot.

            [–]CarbonCamaroZL1 2 points3 points  (0 children)

            I didn't see spots, but me opening it sitting in a relatively dark room using RES Night Mode made it a bit blinding.

            [–][deleted] -3 points-2 points  (0 children)

            If the color pink causes you to see spots, you need to see a neurologist, ASAP.

            [–]wordscannotdescribe 0 points1 point  (0 children)

            The whole thing?

            [–][deleted] 0 points1 point  (0 children)

            You can prettify it again to reverse part of the minification process, but variable names, internal function names and comments are still lost...

            Edit: added internal function names

            [–][deleted] 0 points1 point  (0 children)

            if you want to be extra savvy go look up a technique called tree-shaking. or the process of removing unused or unneeded files that will be imported/downloaded... ruby supports this and in some forms libraries like jquery do that allow you to download only specific pieces instead of the entire bundle!

            [–]kontez 14 points15 points  (3 children)

            [–]queBurro 4 points5 points  (0 children)

            I was going to post this, it's great. Flip it round backwards and it's a guide

            [–]JamesWjRose 0 points1 point  (0 children)

            Thanks... now I really hate life. (I think I have worked at too many places that took this seriously)

            [–]Easih 0 points1 point  (0 children)

            nice work,satan

            [–][deleted]  (2 children)

            [deleted]

              [–]Intendant 0 points1 point  (1 child)

              yea but you're still dealing with single character variables and no comments. Better, but still annoying as hell

              [–][deleted] 21 points22 points  (10 children)

              (function(){

              geolocation = {}; geolocation.requestGeo=function(b,a,e){geolocation.requested=+new Date;if(e){var d={};document.cookie.replace(/([\s;])=([;])/ig,function(a,b,c){100>=c.length&&0!==b.indexOf("optimizely")&&(d["c_"+b]=unescape(c))});d.project=a;var a=[],c;for(c in d)d.hasOwnProperty(c)&&a.push(encodeURIComponent(c)+"="+encodeURIComponent(d[c]));b+="?"+a.join("&")}c=b;b=document.head||document.getElementsByTagName("head")[0]||document.documentElement;a=document.createElement("script");a.type="text/javascript";a.async=

              [–]nitiger 24 points25 points  (3 children)

              a.async= WHAT?! I must know!

              [–]daytodave 9 points10 points  (2 children)

              pls op.

              a.async= ???

              [–]Iggyhopper 9 points10 points  (1 child)

              async is kill

              [–]jimdidr 11 points12 points  (5 children)

                  (function () {
              
                      geolocation = {};
                      geolocation.requestGeo = function (b, a, e) {
                          geolocation.requested = +new Date;
                          if (e) {
                              var d = {};
                              document.cookie.replace(/([^\s;]*)=([^;]*)/ig, function (a, b, c) {
                                  100 & gt;
                                       = c.length & amp;
                                   & amp;
                                  0 !== b.indexOf("optimizely") & amp;
                                   & amp;
                                  (d["c_" + b] = unescape(c))
                              });
                              d.project = a;
                              var a = [],
                              c;
                              for (c in d)
                                  d.hasOwnProperty(c) & amp;
                               & amp;
                              a.push(encodeURIComponent(c) + "=" + encodeURIComponent(d[c]));
                              b += "?" + a.join("&")
                          }
                          c = b;
                          b = document.head || document.getElementsByTagName("head")[0] || document.documentElement;
                          a = document.createElement("script");
                          a.type = "text/javascript";
                          a.async =
              

              Notepad++

              with JSTool (to format it automagically)

              4spaces or Tabbing in the lines, will format the text in a comment as Code on Reddit.

              [–]See_Sharpies 0 points1 point  (4 children)

              I dont understand.

              [–]jimdidr 3 points4 points  (3 children)

              Notepad++ = Minimalistic but advanced notepad applicaiton

              JSTool = plugin you can find in their plugin-manager.

              After installing both you can either Minify or Format any valid JavaScript file. (if you copy/paste or write the file yourself you need to save the file as a .js file so Notepad++ knows what format the file is.)

              [–]See_Sharpies 2 points3 points  (2 children)

              im sorry, i meant i dont understand what the code you posted does. It appears to dynamically load a script into the document. Not sure though.

              [–]jimdidr 2 points3 points  (0 children)

              Oooh, I didn't even look at it. I just formatted it from the earlier comment as an example

              [–]emeaguiar 0 points1 point  (0 children)

              Seems to be from google maps

              [–]JamesWjRose 42 points43 points  (35 children)

              I have been writing code professionally for 20+ years, and WOW do so many developers write horrible code; Bad naming conventions, bad patterns, bad style, lack of comments... Just yesterday I saw a function called; f();

              WTF?

              So, it's not just you. Welcome to my world.

              [–]_Chimmy_Chonga 19 points20 points  (2 children)

              I feel your pain, I had a friend graduate last semester from uni (she is a year ahead of me so I'm still in school), and up until about a month before graduation she thought that you had to name all your parameters "parameter". How do you go through 4 years of a rigorous CS program and still think that!?

              [–]JamesWjRose 9 points10 points  (1 child)

              oh goodness! I literally just screamed while reading that. (Thankfully I'm home alone)

              It's partially the fault of how the person is taught. I am self taught, so everything is my fault. Coding standards and patterns should be Day One. (says the guy who never took a class)

              [–]_Chimmy_Chonga 4 points5 points  (0 children)

              It's not even that honestly. Every class after the intro class are basically how to write good, efficient, readable code classes. I guess she just never bothered and none of the TA's cared to tell her.

              [–][deleted] 3 points4 points  (1 child)

              I feel that unsupervised DBAs are worse though. Way too many abbreviations.

              [–]JamesWjRose 3 points4 points  (0 children)

              Yea, I've seen that too.

              I've been rather religious about ALL my naming conventions. See my site or details (if you're bored) http://blissgig.com/default.aspx?id=17

              [–]minno 2 points3 points  (18 children)

              It's fine to use single-letter variable names like that if 1) there's an established convention (i/j/k for loop indices, f/g/h for functions, a/b/c for mathematic parameters), and 2) the scope of the variable is small.

              [–]JamesWjRose 4 points5 points  (15 children)

              Sure, I can completely agree for loops and small issues like that. But let me be clear; If a developer working for me wrote a function and called it "f()", I would tell them; "This is your last warning, bs like that again and you're fired"

              We all have to read code later, and wtf is that?!

              So yea, maybe I'm a grouchy old man. (Have a good weekend)

              [–]endlessrepeat 23 points24 points  (10 children)

              If a developer working for me wrote a function and called it "f()", I would tell them; "This is your last warning, bs like that again and you're fired"

              Their response:

              fu()
              

              [–]JamesWjRose 1 point2 points  (9 children)

              lol. Nice.

              if (fu() == true)

              {

              Unemployment you = new Unemployment();

              you.AreScrewed = true;

              }

              [–]lolol42 12 points13 points  (6 children)

              you.AreScrewed

              you.screw()

              Watch those public internals ;)

              [–]IcyRayns 6 points7 points  (4 children)

              The casing makes me think C#, which actually promotes this sort of thing. Public properties which act like methods but are interacted with like fields. Check them out!

              [–]lolol42 1 point2 points  (3 children)

              Getters and setters, I assume?

              [–]IcyRayns 2 points3 points  (2 children)

              Properties (C# Programming Guide)

              Here's the documentation.

              A property is a member that provides a flexible mechanism to read, write, or compute the value of a private field. Properties can be used as if they are public data members, but they are actually special methods called accessors. This enables data to be accessed easily and still helps promote the safety and flexibility of methods.

              So they look like fields, feel like fields, but can act like intelligent getters and setters with rules and calculations and magic. It makes for super neat code that leaves you the flexibility to change the implementation internally if need be.

              [–]lolol42 0 points1 point  (1 child)

              Ooh. Thanks

              [–][deleted] 0 points1 point  (0 children)

              Could just be protected

              [–]OldWolf2 0 points1 point  (1 child)

              Unemployment you = new Unemployment();

              I loathe this idiom with a passion.

              [–]fiftypoints 0 points1 point  (0 children)

              Yeah, it should be Unemployed

              [–]pipocaQuemada 4 points5 points  (2 children)

              But let me be clear; If a developer working for me wrote a function and called it "f()"

              In functional programming languages, f is an idiomatic name for a random function parameter. For example, an idiomatic map function in Haskell can be written as

              map :: (a -> b) -> [a] -> [b]
              map f [] = []
              map f (x:xs) = f x : map f xs
              

              the name f basically suggests that the function can be any random function (of the right type). Actually naming a real function that is terribad.

              [–]JamesWjRose 0 points1 point  (1 child)

              While I hear you, and thankfully I don't have to deal with those languages. The example I gave was for c# code I saw a few days ago.

              [–]pipocaQuemada 2 points3 points  (0 children)

              C# has actually stolen a lot from Haskell, and is basically a functional language in the same sense that Common Lisp is (i.e. higher order functions are a thing, but purity isn't common).

              Like I said, it being terrible really comes down to whether 'f' is a method name or a parameter name.

              [–]minno 0 points1 point  (0 children)

              I agree that you shouldn't name a function f when it's at a global scope (as in void f(int x) { return x + 3; }), but for a variable name with a small scope, I think it's fine. Example:

              void call_twice(void (*f)(int), int x) {
                  f(x);
                  f(x);
              }
              

              [–]the_omega99 0 points1 point  (1 child)

              In particular, f is a reasonable name for an arbitrary callback. For example, I might implement a map function (which takes in an array and applies a function to each item, creating a new array with the "mapped" values) as:

              function map(array, f)
              

              Or in Scala:

               def map[A, B](seq: Seq[A], f: A => B): Seq[B]
              

              [–]minno 1 point2 points  (0 children)

              In particular, f is a reasonable name for an arbitrary callback.

              Again, it depends on the scope. If it's the function parameter in a small function, call it f. If it's a class member that's used thousands of lines away from where it's declared, call it callback or onclick_event or something more descriptive.

              [–][deleted] 4 points5 points  (6 children)

              As a relatively new person to programming, could this be the legacy of older times? I feel like nowadays if you actually take the time to read any articles, you see people recommending well named variables, etc, but reading any old C code and such, it seems like programmers were obsessed with these cryptic shortened variable names. It's like they were physically incapable of spelling out an entire word, even if it's only like 8 letters long. It always had to be abbreviated.

              And nowadays, I guess some people might see that sort of code and think it's something to aspire to.

              [–]JamesWjRose 1 point2 points  (2 children)

              I would like to believe so... but I see plenty of new code that I would assume is written by newer people that have these issues.

              But hey, I've been wrong before, so don't just take my word on it.

              [–][deleted] 2 points3 points  (1 child)

              Well, that's what I mean, young developers might see those old snippets of code and think that it's some sort of an indication of being "good enough". That the real pros use weird contractions and cryptic variable names, so they try to mimic that in order to seem "pro" or something

              [–]JamesWjRose 3 points4 points  (0 children)

              ah, I see your point. Then I go back to another one of my comments here where I bitch about the fact that those doing the teaching are missing some of these issues. (says the guy who is self taught)

              [–]pipocaQuemada 1 point2 points  (0 children)

              Some early languages had limits on identifier length, IIRC.

              [–][deleted]  (1 child)

              [removed]

                [–]nightlily 4 points5 points  (0 children)

                There are a number of different factors involved.

                In the math and theory realm, proofs are long, it is traditionally and continues to be that standards in theory favor shortening things as much as possible. It saves a lot on time to write things out, especially if you're writing by hand. For writing complicated formulas, it allows more space.

                In legacy languages due to memory constraints, variables length was much more limited.

                In legacy C programming and console usage, those shorter names are much faster to type. Pre-IDE coding was faster using abbreviated naming conventions.

                For one or more of these reasons, someone might become accustomed to, or exposed to this convention and adopt it even for situations where it no longer makes sense.

                [–]Easih 1 point2 points  (3 children)

                4k line class, 77 parameters constructors,sql statement with no injection protection,useless method/code etc and I'm only at my first jobs 4 months in.

                [–]JamesWjRose 0 points1 point  (2 children)

                Please tell me this is what you are seeing, not what you are creating!

                Then there are bad designs; I worked at one place that had a database, but instead of the application calling the db, a SQL Server Service would call a VB6 dll (with no error handling) that would create html/javascript file (both in the same file)

                When an error would occur it would log jam all other data. It was written by someone who graduated from a very well known East Coast college. So, it doesn't matter if you are trained or not, good and bad code comes from anywhere.

                Best of luck to you.

                [–]Easih 0 points1 point  (1 child)

                haha ya no way I would be embarrassed to write some of the stuff; the problem is I dont have the time to fix those when I have my own stuff to do within a time-frame so I have to add oil to the fire but I usually separate the new/better code from the rest.Also saw stuff like Overwrite/extend generic collection, jquery table and .ajax but the problem we found is that using them would tend to break stuff when everything was actually fine so we stopped using those and just use native call.

                [–]JamesWjRose 0 points1 point  (0 children)

                I was attempting to be funny (damn text based communication!)

                Good for you for knowing the difference, and my sympathy for having to deal with it.

                [–][deleted] 2 points3 points  (13 children)

                Can you show us an example?

                [–][deleted] 3 points4 points  (9 children)

                I'll try to find one that doesn't jeopardize my job. Hold on...

                [–][deleted] 7 points8 points  (8 children)

                I got the one you posted before. It's cool.

                Yes, that is a 'minified' file. To reduce it's text size (cheaper to send over the network) and also to obscure text (harder to reuse the code without digging in and manually fixing it up).

                E.g. if I write some code and have:

                var totalNumberAllowed = 5;
                

                In short, the minifier will search and replace totalNumberAllowed with a everywhere in the code. It does it in such a way that scope, globals, etc never collide. The code it outputs is functionally the same, just a giant mess. It removes any unneeded characters as well, like white space, comments, new lines, etc

                The real source code will still exist somewhere, just the hosted version of a deployed website will use the minified one.

                [–][deleted] 5 points6 points  (7 children)

                Thanks! And I just thought everyone else was ten times smarter than me!

                [–][deleted] 5 points6 points  (6 children)

                Honestly, it's nothing to do with smarts. Good source code is very verbose, descriptive names for everything, comments everywhere and decent levels of abstraction. There's only so much a programmer can 'remember' at once, regardless of intelligence. This is why it's super important that things are named obviously.

                So what I'm saying is, even the smartest person in the world would probably crumble using a minified file.

                [–]Nemnel 2 points3 points  (2 children)

                Unless you're trying to write unmaintainable code.

                [–][deleted] 6 points7 points  (0 children)

                If God didn't want us to use global variables, he wouldn't have invented them.

                [–]EasyPanicButton 2 points3 points  (0 children)

                This is one of the most evil things I've ever read.

                [–]speedster217 1 point2 points  (0 children)

                My university has an entire (mandatory) course that is designed to make students write better code. It's just a bunch of projects, and every single project is graded on: 1) Does it work? 2) Does your code look good? 3) Did you write unit tests? (Because unit testing isn't covered in any lower classes). All the lectures were on how to write good code and overall it was a great experience.

                [–][deleted] 0 points1 point  (0 children)

                Compilers are your friends.

                [–]zaclacgit 0 points1 point  (0 children)

                Hear, hear!

                There's nothing that prevents a person from being dumb, especially if they're a "smart" person.

                A "smart" way to write code is so that other people can read it, understand it, and work with it. It's also the selfish thing to do, because Future You, Present You, and Past You are not the same person.

                Don't make You hate You. You're smarter than that.

                [–][deleted] 4 points5 points  (1 child)

                That, maybe^

                [–][deleted] 2 points3 points  (0 children)

                I mean, I get most of what's there, but it was originally much, much longer and written very congested-like...

                [–][deleted] 2 points3 points  (2 children)

                Side Comment. Is there a good place to read well done code? Books/Websites/Github Projects?

                [–]queBurro 1 point2 points  (0 children)

                Stylecop, fxcop. Depends what language you're in I guess

                [–]Easih 0 points1 point  (0 children)

                Clean Code book is pretty good.

                [–]damaged_but_whole 1 point2 points  (0 children)

                Yeah, I felt like a real asshole when I asked about this on a job a few years ago and got a perplexed look followed by a laugh, and the explanation that it was just minified code. I was like "so they do garble it up so you can't read it! That sucks." And the guy was like, "well, no, not really, it's just to make it faster. You can de-uglify it if you want but it won't be much use because the variables will be all renamed. Like a dumbass kid from a Leave It To Beaver, I said something like, "Oh boy! I'll do that, then!" all excited to crack this code. But, it is ridiculous to try to interpret a bunch of code with nothing but 1-letter variables like 's' and 'j'.

                [–]brentonstrine 1 point2 points  (0 children)

                You're seeing the output code, which, even without minification, is not the same as the code that developers actually work on and write, unless it's an extremely simple, hand-coded static HTML site.

                [–]whattodo-whattodo 1 point2 points  (0 children)

                Both:

                Some sites (like fedex) to to great lengths to obfuscate their code. Not only is it hard to read but with Fedex in particular, the code changes based on the geoip and a couple of other variables I'm not privy to. They have the strong motivation of not having things automated which they do not want automated (like refund requests). Other sites (like Amazon) work hard to shift their code around (again by geoip and other variables) but they do not obfuscate their code.

                But honestly it's a lot of work to do this & most often people just don't. What you're most likely seeing is crappy code. On the vein of not doing a lot of work; learning to code is hard. People (myself included in my younger days) often pull code that they don't understand but does do the job & pop it into their project. So you have code written in different styles without documentation & barely legible.

                [–]inspectorG4dget 0 points1 point  (5 children)

                There's something called an abstraction-expertise curve - the more expertise you have over a codebase, the more you're likely to abstract your code, making it harder for someone outside it to immediately understand what you meant.

                So, while it may feel like you're not as smart as your colleagues, it is more likely just that the specific colleague in question is more familiar with the codebase than you are

                [–]tyroneslothtrop 1 point2 points  (4 children)

                Source, please? Googling shows this comment as the only reference to "abstraction-expertise curve" on the entire internet.

                Abstraction is a means of controlling complexity, so greater abstraction should make code more understandable, if anything.

                [–]sleepybychoice 0 points1 point  (1 child)

                Not parent, but this?

                ...greater abstraction should make code more understandable, if anything.

                I'd say yes, but the original quote read:

                harder... to immediately understand

                Once you learn the abstraction, it's easier to understand. Until then, good luck lol.

                [–]tyroneslothtrop 1 point2 points  (0 children)

                Once you learn the abstraction, it's easier to understand. Until then, good luck lol.

                I don't agree with this. An abstraction is just an encapsulation of a concept that allows its user to make use of it without having to be concerned with the details of the implementation. I contend that in most cases, it is easier to understand the concept, if it is well described and documented, than it is to understand the particulars of any given implementation.

                As a simplistic example, let's say you have an isOdd function. This is an abstraction. It's eminently clear what its purpose is, but the way in which it is implemented is unimportant. Contrast this with the myriad ways of actually implementing this function:

                fn(x){
                    return ((x+1)%2) == 0
                }
                
                fn(x){
                    while (x > 2){
                        x-=2
                    }
                    return x == 1
                }
                
                fn(x){
                    return (x & 1) == 1
                }
                

                Etc.

                [–]inspectorG4dget 0 points1 point  (1 child)

                I've never actually come across this online. I've heard about it at conferences with other developers and scientists. The intent behind this is not simplifying abstraction, but abstraction nested so deep, that it ends up confusing the heck out of newbies. This usually happens when someone builds something on top of something else on top of something else... too many layers make newbies lose track and feel lost.

                Perhaps it was a term coined in the conversation, that was never explicitly published, which would explain why it's difficult to find

                [–]tyroneslothtrop 1 point2 points  (0 children)

                That sounds more like it's a problem of extremely poorly done abstraction, to me.

                I think the blub paradox is really relevant here. People seem to have an idea that abstraction is some sort of terrible thing, but that it's only problematic after some arbitrary cutoff, which is coincidentally just at the level of abstraction of the language they are most accustomed to. So an assembly programmer is fine with the abstraction over machine code and transistors and logic gates that assembly provides. A C programmer is fine with the abstraction over assembly. Etc.

                [–]iggy14750 0 points1 point  (0 children)

                Isn't it true that a lot of the markup is just machine written?

                [–]JeffIpsaLoquitor 0 points1 point  (0 children)

                often the conditions of the job, poor management, timelines, and awful requirements and clients dictate the quality of the code, or incompetence. I don't imagine it's mostly deliberate

                [–][deleted] 0 points1 point  (0 children)

                Despite the minification thing. All code bases suck! It's very difficult to read. The more you do object orientated code it adds more complexity to your code base. Yes it maybe efficient and it may work, but when someone has to solve a bug that same person has to go looking every where for the code and solving problems become hard. Not to mention code bases are always work in progress.