Skip to main content
deleted 4 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

sed 's/\(\/\/\|#\).*$//g' YOUR_FILENAME | sed '/^$/N;/^\s*$/D'

Edit:

sed 's/\(\/\/\|#\).*$//g' YOUR_FILENAME | sed '/^$/N;/^\s*$/D' 

To clarify, that strips comments and multiple blank lines. Generally comments are a good idea. I would not remove them or create shorter names for functions and variables for performance. Any benefit there is minuscule beyond belief. Your comments trolled me into giving that answer, seriously though: remove your comments.

Ignoring the Comments - some real recommendations

Consistency makes things easier to read.

  1. Work out your maximum line length and use it (especially for the comments).
  2. Stop trolling me with mixed brace styles in ifif/elseelse statements.

make_checks is not a very descriptive name for a function. It would be better as check_libraries.

Now, the bit of your code that actually does something:

$type = ( substr($file, -4, 1) !== '.' ) // Can you see? ? substr($file, -4) // Can you see my genius. : substr($file, -3) // It's shining... ; // oh so bright. What a marvelous function, I // couldn't have done it better myself. Oh, wait. 

Should be rewritten:

$type = pathinfo($file, PATHINFO_EXTENSION);

$type = pathinfo($file, PATHINFO_EXTENSION); 

In fact, the variables $file$file and $type$type are only used once (and hence shouldn't even be variables).

sed 's/\(\/\/\|#\).*$//g' YOUR_FILENAME | sed '/^$/N;/^\s*$/D'

Edit:

To clarify, that strips comments and multiple blank lines. Generally comments are a good idea. I would not remove them or create shorter names for functions and variables for performance. Any benefit there is minuscule beyond belief. Your comments trolled me into giving that answer, seriously though: remove your comments.

Ignoring the Comments - some real recommendations

Consistency makes things easier to read.

  1. Work out your maximum line length and use it (especially for the comments).
  2. Stop trolling me with mixed brace styles in if/else statements.

make_checks is not a very descriptive name for a function. It would be better as check_libraries.

Now, the bit of your code that actually does something:

$type = ( substr($file, -4, 1) !== '.' ) // Can you see? ? substr($file, -4) // Can you see my genius. : substr($file, -3) // It's shining... ; // oh so bright. What a marvelous function, I // couldn't have done it better myself. Oh, wait. 

Should be rewritten:

$type = pathinfo($file, PATHINFO_EXTENSION);

In fact the variables $file and $type are only used once (and hence shouldn't even be variables).

sed 's/\(\/\/\|#\).*$//g' YOUR_FILENAME | sed '/^$/N;/^\s*$/D' 

To clarify, that strips comments and multiple blank lines. Generally comments are a good idea. I would not remove them or create shorter names for functions and variables for performance. Any benefit there is minuscule beyond belief. Your comments trolled me into giving that answer, seriously though: remove your comments.

Ignoring the Comments - some real recommendations

Consistency makes things easier to read.

  1. Work out your maximum line length and use it (especially for the comments).
  2. Stop trolling me with mixed brace styles in if/else statements.

make_checks is not a very descriptive name for a function. It would be better as check_libraries.

Now, the bit of your code that actually does something:

$type = ( substr($file, -4, 1) !== '.' ) // Can you see? ? substr($file, -4) // Can you see my genius. : substr($file, -3) // It's shining... ; // oh so bright. What a marvelous function, I // couldn't have done it better myself. Oh, wait. 

Should be rewritten:

$type = pathinfo($file, PATHINFO_EXTENSION); 

In fact, the variables $file and $type are only used once (and hence shouldn't even be variables).

Final line was misleading, I'm not going to write what it boils down to.
Source Link
Paul
  • 4k
  • 2
  • 23
  • 38

sed 's/\(\/\/\|#\).*$//g' YOUR_FILENAME | sed '/^$/N;/^\s*$/D'

Edit:

To clarify, that strips comments and multiple blank lines. Generally comments are a good idea. I would not remove them or create shorter names for functions and variables for performance. Any benefit there is minuscule beyond belief. Your comments trolled me into giving that answer, seriously though: remove your comments.

Ignoring the Comments - some real recommendations

Consistency makes things easier to read.

  1. Work out your maximum line length and use it (especially for the comments).
  2. Stop trolling me with mixed brace styles in if/else statements.

make_checks is not a very descriptive name for a function. It would be better as check_libraries.

Now, the bit of your code that actually does something:

$type = ( substr($file, -4, 1) !== '.' ) // Can you see? ? substr($file, -4) // Can you see my genius. : substr($file, -3) // It's shining... ; // oh so bright. What a marvelous function, I // couldn't have done it better myself. Oh, wait. 

Should be rewritten:

$type = pathinfo($file, PATHINFO_EXTENSION);

In fact the variables $file and $type are only used once (and hence shouldn't even be variables).

sed 's/\(\/\/\|#\).*$//g' YOUR_FILENAME | sed '/^$/N;/^\s*$/D'

sed 's/\(\/\/\|#\).*$//g' YOUR_FILENAME | sed '/^$/N;/^\s*$/D'

Edit:

To clarify, that strips comments and multiple blank lines. Generally comments are a good idea. I would not remove them or create shorter names for functions and variables for performance. Any benefit there is minuscule beyond belief. Your comments trolled me into giving that answer, seriously though: remove your comments.

Ignoring the Comments - some real recommendations

Consistency makes things easier to read.

  1. Work out your maximum line length and use it (especially for the comments).
  2. Stop trolling me with mixed brace styles in if/else statements.

make_checks is not a very descriptive name for a function. It would be better as check_libraries.

Now, the bit of your code that actually does something:

$type = ( substr($file, -4, 1) !== '.' ) // Can you see? ? substr($file, -4) // Can you see my genius. : substr($file, -3) // It's shining... ; // oh so bright. What a marvelous function, I // couldn't have done it better myself. Oh, wait. 

Should be rewritten:

$type = pathinfo($file, PATHINFO_EXTENSION);

In fact the variables $file and $type are only used once (and hence shouldn't even be variables).

Source Link
Paul
  • 4k
  • 2
  • 23
  • 38

sed 's/\(\/\/\|#\).*$//g' YOUR_FILENAME | sed '/^$/N;/^\s*$/D'