Jump to content

Recommended Posts

  • Replies 76
  • Created
  • Last Reply

Top Posters In This Topic

function myFunction()
{
   if($me == "awesome")
   {
      echo "Damn straight.";
   }
   else
   {
      echo "You suck.";
   }
}

I hate making my code like that because i read an optimization article that if you put stuff very close together e.g.

if ($me == "awesome"){ echo "hi"; }else{ echo "you suck"; }

then the server will be able to run the code much faster. or so ive read.

 

Faster, yes.  Much faster? No.  Cramming code together like that has not yielded noticeable differences in a very long time.  The processing time difference between those two are so minute that it's not even considered anymore.  Even with a thousand lines of code with another 1000 lines of comments, 1 for each line of code, we're talking like .000000000000001 second differences here.  And you would have to have a considerably large chunk of code to even measure it.

 

And you're not even looking at this from a larger perspective.  Let's say you really wanted to save those extra pennies. 6 months down the road something changes and the script no longer works.  So some poor soul would have to tredge through all that crap trying to find out what went wrong.  I think all that downtime before he figures it out would be a hell of a lot more than any amount of time you managed to save by doing that.

Link to comment
https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-586524
Share on other sites

function myFunction()
{
   if($me == "awesome")
   {
      echo "Damn straight.";
   }
   else
   {
      echo "You suck.";
   }
}

I hate making my code like that because i read an optimization article that if you put stuff very close together e.g.

if ($me == "awesome"){ echo "hi"; }else{ echo "you suck"; }

then the server will be able to run the code much faster. or so ive read.

 

lmao.

Link to comment
https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-590026
Share on other sites

function myFunction()
{
   if($me == "awesome")
   {
      echo "Damn straight.";
   }
   else
   {
      echo "You suck.";
   }
}

I hate making my code like that because i read an optimization article that if you put stuff very close together e.g.

if ($me == "awesome"){ echo "hi"; }else{ echo "you suck"; }

then the server will be able to run the code much faster. or so ive read.

 

lmao.

 

technicaly he is right but the disadvantages outweigh any mesurable effects which would be miniscule

Link to comment
https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-592549
Share on other sites

Sounds like a member that used to be here who adamantly kept coding without any whitespace whatsoever to save diskspace...

 

ive seen them do that alot, esewpecialy client side scripsts with web apps.

 

Except the JavaScript source code isn't actually written without whitespace.  Instead, it's written normally, meaning in a normal coding style so it can be read/edited, then it's either minified or packed when it's ready to go live.  No one in their right mind intentionally writes code without whitespace.

Link to comment
https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-593047
Share on other sites

Sounds like a member that used to be here who adamantly kept coding without any whitespace whatsoever to save diskspace...

 

ive seen them do that alot, esewpecialy client side scripsts with web apps.

 

Except the JavaScript source code isn't actually written without whitespace.  Instead, it's written normally, meaning in a normal coding style so it can be read/edited, then it's either minified or packed when it's ready to go live.  No one in their right mind intentionally writes code without whitespace.

 

is it good to pack it i havent tried ? i have quite a big framework of js

Link to comment
https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-593217
Share on other sites

The only point in it is reducing bandwidth usage. If you strip all the comments and whitespace then the file will be smaller for the user to download and the site will consequently load faster.

 

i think the benifits are outweighed by the disadvantage

Link to comment
https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-593225
Share on other sites

Uh... I think you miss the point...

 

You develop it with whitespace and comments and upon deployment you "pack" it.

 

Real world example (jQuery):

Unpacked: 97 kB

Packed: 30 kB

Difference: 67 kB

 

On a 256 kbps connection that amounts to approximately 2 seconds.

 

Also, imagine you get 1000 hits per day. That's 65 MB/day or 1.9 GB/month saved.

 

If you gzip the file then the size will come down to 16 kB and then you will have saved 81 kB per request or 2.3 GB/month with the 1000 hits per day mentioned before.

Link to comment
https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-593239
Share on other sites

That explains google's code. Have you ever looked at the source code for even the homepage? I imagine they would need to make sure they're running as efficiently as possible with the number of requests they would get. At 112 million hits a day, if they had the same sizes before and after compression they'd be saving around 257.6 TB. I should start packing my code. I'd never really thought much about it before.

Link to comment
https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-593656
Share on other sites

One thing that has always struck me as odd is that their HTML is total crap and there is CSS and Javascript all over it. If they properly coded it and separated HTML, CSS and Javascript then they would save a lot of bandwidth seeing as it could be cached by the client.

Link to comment
https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-593671
Share on other sites

One thing that has always struck me as odd is that their HTML is total crap and there is CSS and Javascript all over it. If they properly coded it and separated HTML, CSS and Javascript then they would save a lot of bandwidth seeing as it could be cached by the client.

 

so infact it is very usfull and i am  the fool

Link to comment
https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-594452
Share on other sites

No tabs is standard? wtf? I couldn't even imagine typing four spaces before each line... I couldn't be bothered, it'd proper produce RSI lol.  I don't understand why that is necessary at all. And is it saying that you don't have to use ?> at the end of PHP-only documents? 

Link to comment
https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-596751
Share on other sites

And is it saying that you don't have to use ?> at the end of PHP-only documents? 

 

The PHP closing tag is technically only necessary if you need something after the PHP block. An argument for omitting it is that you will prevent any accidental whitespace after which will interfere with things that are dependent on that no output has been sent yet (headers for instance). Such things can be incredibly difficult to debug.

Link to comment
https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-596760
Share on other sites

No tabs is standard? wtf? I couldn't even imagine typing four spaces before each line... I couldn't be bothered, it'd proper produce RSI lol.  I don't understand why that is necessary at all. And is it saying that you don't have to use ?> at the end of PHP-only documents? 

 

 

In some editors, you can hit tab, and it will put 4 spaces.  I do prefer tabs though....

Link to comment
https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-597151
Share on other sites

In some editors, you can hit tab, and it will put 4 spaces.

That would be handy. I read somewhere (and may be wrong) that Python determines blocks of code by the four-space method instead of using braces. Is that true? Like you would have something like

if (condition)

    do this

    and this

    and then this

end if

 

or something to that effect. If i didn't have an editor like that, it'd drive me nuts. I may have misread that info though.

Link to comment
https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-597524
Share on other sites

In some editors, you can hit tab, and it will put 4 spaces.

That would be handy. I read somewhere (and may be wrong) that Python determines blocks of code by the four-space method instead of using braces. Is that true? Like you would have something like

if (condition)

    do this

    and this

    and then this

end if

 

or something to that effect. If i didn't have an editor like that, it'd drive me nuts. I may have misread that info though.

 

Python does use indention for that purpose, but what you use to indent doesn't matter as long as you are consistent. You could use one space, two spaces, three spaces, a tab, etc. - it really doesn't matter as long as you don't mix it up.

Link to comment
https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-597813
Share on other sites

In some editors, you can hit tab, and it will put 4 spaces.

That would be handy. I read somewhere (and may be wrong) that Python determines blocks of code by the four-space method instead of using braces. Is that true? Like you would have something like

if (condition)

    do this

    and this

    and then this

end if

 

or something to that effect. If i didn't have an editor like that, it'd drive me nuts. I may have misread that info though.

 

Python does use indention for that purpose, but what you use to indent doesn't matter as long as you are consistent. You could use one space, two spaces, three spaces, a tab, etc. - it really doesn't matter as long as you don't mix it up.

 

Thanks for clearing that up. I'd like to learn Python someday. I've heard good things about it.

Link to comment
https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-597886
Share on other sites

It depends on if i use an IDE and what language.

 

normally in php i just use dreamweaver and using the enter for every curley bracket becomes annoying

so i use nr 1. how ever if i use eclipse or flash develope for developing flash c++ or java it automaticly creates the nr 2 notation so i let it be for what it is

Link to comment
https://forums.phpfreaks.com/topic/110866-coding-style/page/2/#findComment-598413
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.