Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 Examples  





2 Code density of different languages  





3 Reducing bloat  





4 See also  





5 References  














Code bloat






Español
فارسی

 

Edit links
 









Article
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Cite this page
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 


Incomputer programming, code bloat is the production of program code (source codeormachine code) that is perceived as unnecessarily long, slow, or otherwise wasteful of resources. Code bloat can be caused by inadequacies in the programming language in which the code is written, the compiler used to compile it, or the programmer writing it. Thus, while code bloat generally refers to source code size (as produced by the programmer), it can be used to refer instead to the generated code size or even the binary file size.

Examples[edit]

The following JavaScript algorithm has a large number of redundant variables, unnecessary logic and inefficient string concatenation.

// Complex 
function TK2getImageHTML(size, zoom, sensor, markers) {
    var strFinalImage = "";
    var strHTMLStart = '<img src="';
    var strHTMLEnd = '" alt="The map"/>';    
    var strURL = "http://maps.google.com/maps/api/staticmap?center=";
    var strSize = '&size='+ size;
    var strZoom = '&zoom='+ zoom;
    var strSensor = '&sensor='+ sensor;    
   
    strURL += markers[0].latitude;
    strURL += ",";
    strURL += markers[0].longitude;
    strURL += strSize;
    strURL += strZoom;
    strURL += strSensor;
    
    for (var i = 0; i < markers.length; i++) {
        strURL += markers[i].addMarker();
    }
    
    strFinalImage = strHTMLStart + strURL + strHTMLEnd;
    return strFinalImage;
};

The same logic can be stated more efficiently as follows:

// Simplified 
const TK2getImageHTML = (size, zoom, sensor, markers) => {
    const [ { latitude, longitude } ] = markers;
    let url = `http://maps.google.com/maps/api/staticmap?center=${ latitude },${ longitude }&size=${ size }&zoom=${ zoom }&sensor=${ sensor }`;

    markers.forEach(marker => url += marker.addMarker());

    return `<img src="${ url }" alt="The map" />`;
};

Code density of different languages[edit]

The difference in code density between various computer languages is so great that often less memory is needed to hold both a program written in a "compact" language (such as a domain-specific programming language, Microsoft P-Code, or threaded code), plus an interpreter for that compact language (written in native code), than to hold that program written directly in native code.

Reducing bloat[edit]

Some techniques for reducing code bloat include:[1]

See also[edit]

References[edit]

  1. ^ "Code bloat". DocForge. Archived from the original on 5 March 2016. Retrieved 30 December 2009.

Retrieved from "https://en.wikipedia.org/w/index.php?title=Code_bloat&oldid=1221341175"

Categories: 
Software optimization
Software engineering folklore
Hidden categories: 
Articles with short description
Short description matches Wikidata
Articles needing additional references from June 2014
All articles needing additional references
Articles needing additional references from August 2013
 



This page was last edited on 29 April 2024, at 10:31 (UTC).

Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



Privacy policy

About Wikipedia

Disclaimers

Contact Wikipedia

Code of Conduct

Developers

Statistics

Cookie statement

Mobile view



Wikimedia Foundation
Powered by MediaWiki