New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is Code Bloat? #2343

Open
PopVeKind opened this Issue Dec 21, 2017 · 3 comments

Comments

Projects
None yet
1 participant
@PopVeKind
Contributor

PopVeKind commented Dec 21, 2017

Technical details regarding my environment

YOURLS version: 1.7.3
    Plugins enabled: none
PHP version: PHP Version 7.0.22-0ubuntu0.16.04.1

Defining Code Bloat

In a nutshell:
Code Bloat is unnecessary code that is run on every request, which is only needed by a few users.

Types of Code Bloat

  1. Feature Code Bloat. Code for some feature. Should be a Plugin!
  2. Logic Settings Code Bloat. Code that triggers logic vs literal code to insert.
  3. Corrective Code Bloat. Bad code to correct other bad code.

Economics of Code Bloat

  1. Performance (slows execution time)
  2. Delayed Development of Code
  3. Hard to Read Code

The Goal

The goal of this thread (issue) is to talk with other developers about what is Code Bloat in YOURLS and how to both prevent it and remove it from the YOURLS code.

@PopVeKind

This comment has been minimized.

Show comment
Hide comment
@PopVeKind

PopVeKind Dec 22, 2017

Contributor

December 2018

Before we look at the types of Code Bloat, let's take a look at a possible YOURLS future.

I find it a benefit to battle Code Bloat with possible near future plans and goals.

Read this carefully - as if we are now traveling to the future...

One Year From Now...

Full-Fledged Installer

YOURLS now has Full-Fledged Installer #1254 It asks for only the DB information and the first username and password. With this, it builds a proper config file that only contains the DB info. It builds a $yourls static array that contains all settings, and stores it in the DB. It also stores the username and password in a user table.

Settings Page

YOURLS also has a Settings Page (in the admin area). All constants have been removed from the config file except for DB settings. Core settings are automatically loaded into the $yourls array and saved to the DB on the first admin settings edit. (one mouse click!)

All Settings may now be changed at will. This is because the default behavior is to check any keyword against the DB. If it is in the DB, it is valid.

What used to be YOURLS_URL_CONVERT (now $yourls[ 'charset' ] ) is now used for automatic creation of keywords only. Manually adding or editing a keyword allows any character to be entered, howbeit, with a warning.

$yourls Array

All YOURLS configuration settings are contained together in one array, $yourls.

Core Constants Removed

Constants have been removed from all core files except for DB configuration.

Trailing Slash Problem Eliminated

The $yourls array totally eliminates the need for YOURLS_SITE and eliminates the trailing slash problem.

Plugins Added

Because of the $yourls array, it made it easy to add the following plugins:

  1. MultiSite Plugin (one install to manage several domains) - A Roadmap planned feature.
  2. WordPress Plus YOURLS Plugin - working together without conflict in the document root directory.
  3. Gives YOURLS its Own Directory Plugin
  4. Rename the Admin Directory Plugin
  5. Remove Column of IP Address Plugin - For Private Users - who wants to see a column of their own IP Addresses?
  6. Admin Number of Rows Plugin - Let's you adjust the number of rows in the admin area (now fixed to 15) and save this as your default.

I Believe

With cooperation, I believe this can be finished by the end of December 2018, or even before!

Exciting things are coming!

Reducing the three different types of Code Bloat will help make the above future things happen.

Contributor

PopVeKind commented Dec 22, 2017

December 2018

Before we look at the types of Code Bloat, let's take a look at a possible YOURLS future.

I find it a benefit to battle Code Bloat with possible near future plans and goals.

Read this carefully - as if we are now traveling to the future...

One Year From Now...

Full-Fledged Installer

YOURLS now has Full-Fledged Installer #1254 It asks for only the DB information and the first username and password. With this, it builds a proper config file that only contains the DB info. It builds a $yourls static array that contains all settings, and stores it in the DB. It also stores the username and password in a user table.

Settings Page

YOURLS also has a Settings Page (in the admin area). All constants have been removed from the config file except for DB settings. Core settings are automatically loaded into the $yourls array and saved to the DB on the first admin settings edit. (one mouse click!)

All Settings may now be changed at will. This is because the default behavior is to check any keyword against the DB. If it is in the DB, it is valid.

What used to be YOURLS_URL_CONVERT (now $yourls[ 'charset' ] ) is now used for automatic creation of keywords only. Manually adding or editing a keyword allows any character to be entered, howbeit, with a warning.

$yourls Array

All YOURLS configuration settings are contained together in one array, $yourls.

Core Constants Removed

Constants have been removed from all core files except for DB configuration.

Trailing Slash Problem Eliminated

The $yourls array totally eliminates the need for YOURLS_SITE and eliminates the trailing slash problem.

Plugins Added

Because of the $yourls array, it made it easy to add the following plugins:

  1. MultiSite Plugin (one install to manage several domains) - A Roadmap planned feature.
  2. WordPress Plus YOURLS Plugin - working together without conflict in the document root directory.
  3. Gives YOURLS its Own Directory Plugin
  4. Rename the Admin Directory Plugin
  5. Remove Column of IP Address Plugin - For Private Users - who wants to see a column of their own IP Addresses?
  6. Admin Number of Rows Plugin - Let's you adjust the number of rows in the admin area (now fixed to 15) and save this as your default.

I Believe

With cooperation, I believe this can be finished by the end of December 2018, or even before!

Exciting things are coming!

Reducing the three different types of Code Bloat will help make the above future things happen.

@majordome

This comment has been minimized.

Show comment
Hide comment
@majordome

majordome bot Dec 22, 2017

Thanks for your comment, @PopVeKind!

Your reply is very long.
As a bot, I take less than a second to read it, but summing it up a little bit
will help old-fashioned humans understand your thought.

majordome bot commented Dec 22, 2017

Thanks for your comment, @PopVeKind!

Your reply is very long.
As a bot, I take less than a second to read it, but summing it up a little bit
will help old-fashioned humans understand your thought.

@PopVeKind

This comment has been minimized.

Show comment
Hide comment
@PopVeKind

PopVeKind Dec 27, 2017

Contributor

Types of Code Bloat

Few people realize there are different types of Code Bloat.

  1. Feature Code Bloat. This type of Code Bloat is caused by adding too many features to the core code. Features that add excessive code, or that are used by few users, should be built as plugins.

  2. Logic Settings Code Bloat. This type of Bloat is caused by using logic instead of literals in Core settings. The admin core settings page is accessed maybe one time in years, or at least months. The core files may be accessed many times a second on an active site. Consider the following logic vs literals settings.

    1. Old Style: define( 'YOURLS_URL_CONVERT', 36 );
    2. Logic: $yourls[ 'url_convert' ] = 36;
    3. Literal: $yourls[ 'charset' ] = '0123456789abcdefghijklmnopqrstuvwxyz';
    • ii and iii appear on the Setting Page as an identical choice.
      "generates all lowercase keywords (ie: 13jkm)"
    • i and ii have Logic Settings Code Bloat - Not Needed Code: yourls_get_shorturl_charset()
    • Best Practice - Code added to admin (run once a year) and saved as a literal, is the best practices because it removes code that runs with every request.
  3. Corrective Code Bloat - Sometimes code bloat creeps in while trying to correct a problem. Consider that YOURLS_ADMIN_SSL == true actually means links to admin pages should use the https protocol.

    1. Old Style: define( 'YOURLS_SITE', 'http://sho.rt' );
    2. Literal: $yourls[ 'site' ] = 'http://sho.rt'; // used in short url links. Automatic - No Typing.
    3. Old Style: define( 'YOURLS_ADMIN_SSL', true );
    4. Literal: $yourls[ 'abs_url' ] = 'https://sho.rt'; // used in admin links. The Absolute URL where the files are located. Automatic - No Typing.
    • ii and iv are built automatically and stored in the database.
    • Bloat - yourls_needs_ssl() and yourls_is_ssl() can be removed.
    • Bloat -parts of yourls_site_url(), yourls_get_remote_title(), yourls_match_current_protocol(), yourls_get_relative_url(), and yourls_set_url_scheme() could be removed or replaced by
      $yourls[ 'abs_url' ]
Contributor

PopVeKind commented Dec 27, 2017

Types of Code Bloat

Few people realize there are different types of Code Bloat.

  1. Feature Code Bloat. This type of Code Bloat is caused by adding too many features to the core code. Features that add excessive code, or that are used by few users, should be built as plugins.

  2. Logic Settings Code Bloat. This type of Bloat is caused by using logic instead of literals in Core settings. The admin core settings page is accessed maybe one time in years, or at least months. The core files may be accessed many times a second on an active site. Consider the following logic vs literals settings.

    1. Old Style: define( 'YOURLS_URL_CONVERT', 36 );
    2. Logic: $yourls[ 'url_convert' ] = 36;
    3. Literal: $yourls[ 'charset' ] = '0123456789abcdefghijklmnopqrstuvwxyz';
    • ii and iii appear on the Setting Page as an identical choice.
      "generates all lowercase keywords (ie: 13jkm)"
    • i and ii have Logic Settings Code Bloat - Not Needed Code: yourls_get_shorturl_charset()
    • Best Practice - Code added to admin (run once a year) and saved as a literal, is the best practices because it removes code that runs with every request.
  3. Corrective Code Bloat - Sometimes code bloat creeps in while trying to correct a problem. Consider that YOURLS_ADMIN_SSL == true actually means links to admin pages should use the https protocol.

    1. Old Style: define( 'YOURLS_SITE', 'http://sho.rt' );
    2. Literal: $yourls[ 'site' ] = 'http://sho.rt'; // used in short url links. Automatic - No Typing.
    3. Old Style: define( 'YOURLS_ADMIN_SSL', true );
    4. Literal: $yourls[ 'abs_url' ] = 'https://sho.rt'; // used in admin links. The Absolute URL where the files are located. Automatic - No Typing.
    • ii and iv are built automatically and stored in the database.
    • Bloat - yourls_needs_ssl() and yourls_is_ssl() can be removed.
    • Bloat -parts of yourls_site_url(), yourls_get_remote_title(), yourls_match_current_protocol(), yourls_get_relative_url(), and yourls_set_url_scheme() could be removed or replaced by
      $yourls[ 'abs_url' ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment