Notings of Attention™
Acmlmboard 2 Released
Github/GIT | @acmlmboard
Chatting Places
Discord

Affiliates
Super Mario Bros. X | Kuribo64
Views: 8,986,500
Main | FAQ | IRC chat | Memberlist | Active users | Latest posts | Stats | Ranks | Online users | Search
04-19-24 05:32 AM
Guest: Register | Login

0 users currently in AcmlmBoard Developer Zone | 3 bots

Main - AcmlmBoard Developer Zone - Board code stylization (PHP and MySQL)
Next newer thread | Next older thread


Scrydan
Posted on 07-21-12 03:47 PM, in Link | ID: 21206
Normal User
Scryforce - A place that still exists. Neat.
Level: 86


Posts: 47/2020
EXP: 5948564
Next: 193543

Since: 07-18-12
From: USA

Last post: 766 days
Last view: 748 days
Alright, so I've spoken with Emuz and I think it is time we get this under wraps.
People code differently and have different styles, that's a fact. While we may have similarities, without some kind of template, we will see quite a bit of clashes.

Therefore I decided to create this thread as a way for us to discuss templates relating to all code and queries. Once we get this discussed enough, we should make an effort to rewrite all scripts that violates the discussed template we all agree with.


So with that said, let's begin discussion. Everything from the below is how I write code and is purely opinion based. You may share your own and discuss pros and cons to it.


Loops


Each loop for me usually is always bracketed, regardless of it being needed. I do this so it is easy to tell where it ends and begins without much looking. I also space out the brackets to make them match each other in depth so you can easily trace it in larger loops. The brackets often are one character spaced past the beginning of the loop (not shown, they begin on the f of if)

if ($somevar == "thisismadness")
{
$madness = "This is PHP!";
}


Capitalization


In my opinion, having anything not lowercased is more trouble than it is worth. For some reason any variables with capitalization just bothers me. I understand it can help you see bigger variable names but for that, I just use _. Should you accidentally screw up on capitalization, it will screw with you while you ponder at why perfect code isn't working.

//To be honest, I'd still more likely user $iphistory than the below but this is if you must feel the need to make it stand out.
$ip_history = $whatever; //versus $IpHistory or $ipHistory


Spacing


Much of the older code lacks this. You will see stuff like this.

if($user[email]){
//something
}

//sometimes like this
if($user[email]){ //something }

Which should be spaced in my opinion like so.

if ($user['email'])
{
//something
}

It may not be too much of a problem with one loop but when you see 5 loops back to back with this, it just looks like a mess to me. Only my opinion though. (Also, variable arrays like that should have ' ' in the name of that part of the array.)


Printing/Echoing


I've seen this a few times in code.

$shoplist.="
". " $L[TR] class=\"sfont\">
". " $L[TD1] width=70>$shop[name]</td>
". " $L[TD2]><a href="shop.php?action=desc&id=".$eq[ª".$shop[id]]."'>".$items[$eq['eq'.$shop[id]]][name]."</a>&nbsp;</td>
". " </tr>";
$shoplist .= "</table>";

I feel that there's too many "breaks" in that string when it could all just be like this.

$shoplist .= "
$L[TR] class=\"sfont\">
$L[TD1] width=\"70\">".htmlspecialchars($shop['name'])."</td>
$L[TD2]><a href="\"shop.php?action=desc&id=".$eq[".$shop[id]]."\">".$items[$eq['eq'.$shop[id]]][name]."</a>&nbsp;</td>
</tr>
</table>";

I also notice many times some inconsistencies when HTML is used.

<link rel='stylesheet' href="css/abI.css?tz=-18000&minover= µº"><link href="lib/prettify/sunburst.css" type='text/css' rel='stylesheet' />
<script type='text/javascript' src="lib/prettify/prettify.js‚ÙmþÇ+Š›`µº"></head>
<body style=font-size:68% onload="prettyPrint()">
<table cellspacing=0 class=c1>
<td align=center class="b n1" colspan=3>

The heading alone shows this. There are times where no quotes are used for elements, there are times single quotes are used, then double quotes.

I usually just use double quotes myself and single if it is a javascript function. It isn't too important but it would be neat to get this also template stylized as well.


I think there's more to show than what I have here but I will bring it up as needed. Please discuss what styles you use and such.
We should try to come up with a more unified style so we don't have conflicts. :)

I'll edit this post to bring up more examples. Also we need to discuss MySQL stylization a bit too. Too many times I've seen `example` be used and then other times it lacks ``.

Epele
Posted on 07-21-12 06:14 PM, in Link | ID: 21212
Site Administrator
The Sorceress.
Boing~

Level: 235


Posts: 3710/20774
EXP: 200662846
Next: 1263046

Since: 01-01-12
From: UK

Last post: 835 days
Last view: 6 hours
I can agree on the no brackets stuff.. but if it's just a single.variable.. why not go like
if($lol=="rofl"){ $monkey="peanuts"; }

I find that cleaner than dragging it out across three or four lines for just a simple variable.. Ivcan understand it if it were to else clause for a drag.. but not a simple if.

Typing semi-blind on mobile.. Do excuse.any errors.


The world could always use more heroes!

Arisotura
Posted on 07-21-12 06:57 PM, in Link | ID: 21213
Developer
pancakes
Level: 83


Posts: 285/1868
EXP: 5408412
Next: 23809

Since: 01-05-12
From: France

Last post: 676 days
Last view: 215 days
I agree with this generally, but still wanna say a few things.

As Gywall pointed out, having brackets for one-line if statements makes the code feel more bloated, I'm not a fan of it.

Also, syntax like $user[email] is deprecated I think, it throws E_NOTICE level warnings. The proper thing is $user['email'] (or {$user['email']} if the variable is used inside a double-quoted string). $user["email"] works too but looks kinda meh.

As for SQL well... ` is annoying to type on certain keyboard layouts, namely mine (French azerty): AltGr-7, space.

This brings me to mention prepared queries. The code uses a simple syntax which is nice. However there's an oddity, it seems to be replacing the arguments starting from the end.

I figure it's worth mentioning that I came up with a different syntax for ABXD, one that allows for more flexibility than raw SQL. It supports compacted fieldlists, manipulating table names (for example, prefixing them), and of course escaping user input and all. For example, the following code:
Query("SELECT u.(id, name, sex, powerlevel), t.(id, title) FROM {users} u LEFT JOIN {threads} t ON t.user=u.id WHERE (u.id={0} AND t.title={1}) OR u.name={1}", 1337, "Robert'; DROP TABLE students; -- ");

results in the following query:
SELECT u.id AS u_id, u.name AS u_name, u.sex AS u_sex, u.powerlevel AS u_powerlevel, t.id AS t_id, t.title AS t_title FROM prefix_users u LEFT JOIN prefix_threads t ON t.user=u.id WHERE (u.id=1337 AND t.title='Robert\'; DROP TABLE students; -- ') OR u.name='Robert\'; DROP TABLE students; -- '

This method would for example allow to set the minimal user field list as a variable, so that if you want to change the userlink() function to display more stuff, you don't need to modify all the queries...

____________________
Kuribo64 - melonDS

want some revolution in your coffee?

Scrydan
Posted on 07-21-12 10:37 PM, in Link | ID: 21220
Normal User
Scryforce - A place that still exists. Neat.
Level: 86


Posts: 52/2020
EXP: 5948564
Next: 193543

Since: 07-18-12
From: USA

Last post: 766 days
Last view: 748 days
I can agree with it making the code a bit more bloated and add extra lines. However, it does allow me to see it easier. So it really does depend I suppose.

About the `, I ironically when I first started programming in PHP and MySQL, I didn't know what made that on the keyboard so I copied and pasted from existing ones. Haha. I was so dumb silly back long ago.

Epele
Posted on 07-21-12 10:38 PM, in Link | ID: 21221
Site Administrator
The Sorceress.
Boing~

Level: 235


Posts: 3714/20774
EXP: 200662846
Next: 1263046

Since: 01-01-12
From: UK

Last post: 835 days
Last view: 6 hours
$user["email"] looks kinda tacky..

As for the html. I tend to write it with double quotes.. but we do need to settle on that one.

For queries.. I find it easier to work with the "raw" query. Especially when the query is bloated and complex. Just look at acs.php or frank.php for the example. (It's the same between both)


The world could always use more heroes!

Scrydan
Posted on 07-21-12 10:42 PM, in Link | ID: 21222
Normal User
Scryforce - A place that still exists. Neat.
Level: 86


Posts: 53/2020
EXP: 5948564
Next: 193543

Since: 07-18-12
From: USA

Last post: 766 days
Last view: 748 days
I never use $user["email"] as that bothers me. I leave double quotes for strings and HTML elements.
I mainly use single quotes for $user['email'] as it looks better. And it is depreciated I believe as well to not have quotes.

So if we aren't going to use `` in queries then we might as well make sure all of them look the part. I'm all for middle grounds as long as all the code looks the same but looks good and is efficient. ;)

Arisotura
Posted on 07-21-12 10:46 PM, in Link | ID: 21224
Developer
pancakes
Level: 83


Posts: 286/1868
EXP: 5408412
Next: 23809

Since: 01-05-12
From: France

Last post: 676 days
Last view: 215 days
The `` problem with SQL is that you can't always omit it. Some field names conflict with SQL keywords (namely 'order' fields), so if you don't put them in graves, MySQL will throw an error in your face...

____________________
Kuribo64 - melonDS

want some revolution in your coffee?

Scrydan
Posted on 07-21-12 10:50 PM, in (rev. 2 of 07-21-12 10:50 PM by Scrydan) Link | ID: 21225
Normal User
Scryforce - A place that still exists. Neat.
Level: 86


Posts: 54/2020
EXP: 5948564
Next: 193543

Since: 07-18-12
From: USA

Last post: 766 days
Last view: 748 days
Then I suppose we should try to always use them then. At least for consistency sake. I always do so myself so it is nothing new for me.

Edit: Even if I have to be the one to edit all the queries, I will. I can be determined. XD

Emuz
Posted on 07-22-12 04:01 PM, in Link | ID: 21266
Site Administrator

11 Hit Combo:
Mother's Rosario
Level: 108


Posts: 862/3392
EXP: 13242536
Next: 277963

Since: 12-30-11
From: Akron, Ohio; USA

Last post: 137 days
Last view: 11 days
The one thing we need to do is start using the new layout functions exclusively, and start converting the old pages to match.

Some compromise will need to be made. I will not approve a standard coding style unless all of us agree. :)

The Dynamic Profile Administratorâ„¢


"Never Knows Best"
Note: if you can see this my layout broke. ALL THE CREDITS WILL BE REVEALED!!
'Victory Noriko' by @thatsheepagain.
'Chibi Dance Noriko' by @Haru__Kitsu.
'Deity's Night Out (Featuring Gabbie)'
by @thatsheepagain
Noriko Emotes by @Haru__Kitsu.
Side Bar Noriko by @thatsheepagain
'Noriko's Nature Walk' by @projectTiGER_
Emotive Noriko by @thatsheepagain.
"Space Candy Noriko" by BerryVerrine.
"Super Sharp Noriko" by Xionfes.
A gift illustration from the wonderful EverKinzPony!
"Magical Girl Noriko" by @cute_hospital!
"Patient Chibi Noriko" by @Ruii_ki!
'Dapper '60s Noriko' by @thatsheepagain.
'Shiny Chibi Noriko' by @inioli.
'Flower Veil Noriko' by @Sushiee_.
'Noriko in Realism' by @_Sarybuu.
'Noriko's Midnight Adventure' by @projectTiGER_
'Yukata Noriko' by @yunyunmaru_
'Birthday Wishes Noriko' by @thatsheepagain

Arisotura
Posted on 07-22-12 07:11 PM, in Link | ID: 21324
Developer
pancakes
Level: 83


Posts: 288/1868
EXP: 5408412
Next: 23809

Since: 01-05-12
From: France

Last post: 676 days
Last view: 215 days
If we start using the new layout functions, we must make them flexible as I said. Right now, none of them would allow us to reproduce the old pages (namely newreply/newthread/etc) without hardcoding some HTML.

____________________
Kuribo64 - melonDS

want some revolution in your coffee?

Scrydan
Posted on 07-22-12 07:13 PM, in (rev. 2 of 07-22-12 07:14 PM by Scrydan) Link | ID: 21326
Normal User
Scryforce - A place that still exists. Neat.
Level: 86


Posts: 80/2020
EXP: 5948564
Next: 193543

Since: 07-18-12
From: USA

Last post: 766 days
Last view: 748 days
Speaking of functions and HTML, it always has bothered me that the row varibles and whatnot never started with a '<'. I know it contains it but it just looks weird to me. I don't know, it might just be me but I think it should only contain classes for the tags.

I know changing it now would be a lot of work but we may do just that with this reform. So I'm up for the task.

Scrydan
Posted on 07-28-12 10:15 AM, in Link | ID: 21863
Normal User
Scryforce - A place that still exists. Neat.
Level: 86


Posts: 124/2020
EXP: 5948564
Next: 193543

Since: 07-18-12
From: USA

Last post: 766 days
Last view: 748 days
I would like to give a heads up to all developers that I'm going to go through all the / scripts and giving them all the same quotation usage as I've discussed. I already done:
/lib/common.php
/lib/layout.php
acs.php
register.php
login.php
profile.php

I plan to do a lot more today so if you are working on one, please PM me your changes so I can merge them easier. Thanks. It took a lot of time to do just those scripts but in the long run, the aim is to get them all using the same style so it doesn't look as random.

Please PM me any concerns you may have or post them here. I'm also making sure the scripts I work with are spaced evenly now, meaning the first base loop of the script is spaced from the left as close as any loop will get and further loops within other first bases and ect will be further out.

Emuz
Posted on 07-28-12 01:54 PM, in Link | ID: 21872
Site Administrator

11 Hit Combo:
Mother's Rosario
Level: 108


Posts: 910/3392
EXP: 13242536
Next: 277963

Since: 12-30-11
From: Akron, Ohio; USA

Last post: 137 days
Last view: 11 days
Hopefully you won't need to manually merge them. git normally merges them for you. Still a good idea to coordinate with such a low level code change :)

The Dynamic Profile Administratorâ„¢


"Never Knows Best"
Note: if you can see this my layout broke. ALL THE CREDITS WILL BE REVEALED!!
'Victory Noriko' by @thatsheepagain.
'Chibi Dance Noriko' by @Haru__Kitsu.
'Deity's Night Out (Featuring Gabbie)'
by @thatsheepagain
Noriko Emotes by @Haru__Kitsu.
Side Bar Noriko by @thatsheepagain
'Noriko's Nature Walk' by @projectTiGER_
Emotive Noriko by @thatsheepagain.
"Space Candy Noriko" by BerryVerrine.
"Super Sharp Noriko" by Xionfes.
A gift illustration from the wonderful EverKinzPony!
"Magical Girl Noriko" by @cute_hospital!
"Patient Chibi Noriko" by @Ruii_ki!
'Dapper '60s Noriko' by @thatsheepagain.
'Shiny Chibi Noriko' by @inioli.
'Flower Veil Noriko' by @Sushiee_.
'Noriko in Realism' by @_Sarybuu.
'Noriko's Midnight Adventure' by @projectTiGER_
'Yukata Noriko' by @yunyunmaru_
'Birthday Wishes Noriko' by @thatsheepagain

Scrydan
Posted on 08-13-12 08:52 PM, in Link | ID: 23596
Normal User
Scryforce - A place that still exists. Neat.
Level: 86


Posts: 251/2020
EXP: 5948564
Next: 193543

Since: 07-18-12
From: USA

Last post: 766 days
Last view: 748 days
Oh I thought I'd bring this up.

What is everyone's stance on multiple files separating different parts of a system?


Well, more to the point, files like private.php, showprivate.php, sendprivate.php.
At the very least, I think private.php and showprivate.php could be combined into private.php.

What I do not mean are files like thread.php and forum.php as they are quite big already and it doesn't "feel right". Not sure how to explain exactly but yeah. I hope some of you get what I mean.

Emuz
Posted on 08-14-12 12:14 AM, in Link | ID: 23615
Site Administrator

11 Hit Combo:
Mother's Rosario
Level: 108


Posts: 1003/3392
EXP: 13242536
Next: 277963

Since: 12-30-11
From: Akron, Ohio; USA

Last post: 137 days
Last view: 11 days
I agree with the private message system to merge some of the files. It would allow Forwarding, Multiple Recipients and such easier later on.

We'll need to discuss other situations as they come up, but in this case no problems from me at least.

The Dynamic Profile Administratorâ„¢


"Never Knows Best"
Note: if you can see this my layout broke. ALL THE CREDITS WILL BE REVEALED!!
'Victory Noriko' by @thatsheepagain.
'Chibi Dance Noriko' by @Haru__Kitsu.
'Deity's Night Out (Featuring Gabbie)'
by @thatsheepagain
Noriko Emotes by @Haru__Kitsu.
Side Bar Noriko by @thatsheepagain
'Noriko's Nature Walk' by @projectTiGER_
Emotive Noriko by @thatsheepagain.
"Space Candy Noriko" by BerryVerrine.
"Super Sharp Noriko" by Xionfes.
A gift illustration from the wonderful EverKinzPony!
"Magical Girl Noriko" by @cute_hospital!
"Patient Chibi Noriko" by @Ruii_ki!
'Dapper '60s Noriko' by @thatsheepagain.
'Shiny Chibi Noriko' by @inioli.
'Flower Veil Noriko' by @Sushiee_.
'Noriko in Realism' by @_Sarybuu.
'Noriko's Midnight Adventure' by @projectTiGER_
'Yukata Noriko' by @yunyunmaru_
'Birthday Wishes Noriko' by @thatsheepagain

Arisotura
Posted on 08-14-12 08:37 AM, in Link | ID: 23636
Developer
pancakes
Level: 83


Posts: 293/1868
EXP: 5408412
Next: 23809

Since: 01-05-12
From: France

Last post: 676 days
Last view: 215 days
I'd agree to merge some of the files, as long as the final size remains reasonable. I wouldn't want everything to become a huge hub that does 15314 functions...

____________________
Kuribo64 - melonDS

want some revolution in your coffee?

Scrydan
Posted on 08-14-12 03:57 PM, in Link | ID: 23648
Normal User
Scryforce - A place that still exists. Neat.
Level: 86


Posts: 259/2020
EXP: 5948564
Next: 193543

Since: 07-18-12
From: USA

Last post: 766 days
Last view: 748 days
Yeah, I'm mainly speaking of the ones that are like 100 lines or so and can pretty much be one file without being too huge.

Things like forum.php and thread.php should be separated because it would be too big and it would feel weird. So on my branch while fixing up more quotation, I'll also combine a few smaller files and archive more unused ones. I've began the process of the new RPG system but I'm not too sure on the methods we use for queries yet. I've seen some prepared ones and also some $sql->query($query) ones. I've even seen some raw mysql_query functions being used in some.

I'll assume we want prepared ones but my question is:
Is the object $sql really that needed or could we just instead use just a function? I could be wrong though but is it the only way prepared queries can be done with that being used?
I haven't messed with them that much so I wouldn't know 100%.

Emuz
Posted on 08-14-12 05:21 PM, in Link | ID: 23660
Site Administrator

11 Hit Combo:
Mother's Rosario
Level: 108


Posts: 1011/3392
EXP: 13242536
Next: 277963

Since: 12-30-11
From: Akron, Ohio; USA

Last post: 137 days
Last view: 11 days
I think we could switch to a function as long as no one else has a reason why it can't or should be. It would allow for finer grain control, logging, and allow us to keep seeding and salts managed in one place. It would be a bit of work however as that is called in almost every file.

Anyone else have a thought?

The Dynamic Profile Administratorâ„¢


"Never Knows Best"
Note: if you can see this my layout broke. ALL THE CREDITS WILL BE REVEALED!!
'Victory Noriko' by @thatsheepagain.
'Chibi Dance Noriko' by @Haru__Kitsu.
'Deity's Night Out (Featuring Gabbie)'
by @thatsheepagain
Noriko Emotes by @Haru__Kitsu.
Side Bar Noriko by @thatsheepagain
'Noriko's Nature Walk' by @projectTiGER_
Emotive Noriko by @thatsheepagain.
"Space Candy Noriko" by BerryVerrine.
"Super Sharp Noriko" by Xionfes.
A gift illustration from the wonderful EverKinzPony!
"Magical Girl Noriko" by @cute_hospital!
"Patient Chibi Noriko" by @Ruii_ki!
'Dapper '60s Noriko' by @thatsheepagain.
'Shiny Chibi Noriko' by @inioli.
'Flower Veil Noriko' by @Sushiee_.
'Noriko in Realism' by @_Sarybuu.
'Noriko's Midnight Adventure' by @projectTiGER_
'Yukata Noriko' by @yunyunmaru_
'Birthday Wishes Noriko' by @thatsheepagain

Scrydan
Posted on 08-14-12 05:25 PM, in (rev. 2 of 08-14-12 05:27 PM by Scrydan) Link | ID: 23661
Normal User
Scryforce - A place that still exists. Neat.
Level: 86


Posts: 261/2020
EXP: 5948564
Next: 193543

Since: 07-18-12
From: USA

Last post: 766 days
Last view: 748 days
Well, if the task can go to anyone, it can go to me as I'm already cleaning up quotation and other little details. Although I'm sure I'm the most insane here so no one else should have any objections to me doing over nine million changes. ;)

Just let me know what's what and what functions we will keep and I'll work my determined magic. :D

Edit: Someone also work on an error function and I'll begin to replace those as well.

Next newer thread | Next older thread
Main - AcmlmBoard Developer Zone - Board code stylization (PHP and MySQL)


Acmlmboard v2.5.5 (10/04/2020)
© 2005-2024 Acmlm, Emuz, et al.

Page rendered in 0.096 seconds. (1029KB of memory used)
MySQL - queries: 211, rows: 632/665, time: 0.068 seconds.