|
||||||
Views:
11,099,288 |
Main | FAQ | IRC chat | Memberlist | Active users | Latest posts | Stats | Ranks | Online users | Search | 12-03-24 05:26 PM |
||||
Guest: Register | Login |
0 users currently in AcmlmBoard Developer Zone | 2 bots |
Main - AcmlmBoard Developer Zone - Board code stylization (PHP and MySQL) |
Scrydan |
| |||||||
Normal User
Scryforce - A place that still exists. Neat. Level: 86 Posts: 47/2020 EXP: 6104815 Next: 37292 Since: 07-18-12 From: USA Last post: 994 days Last view: 976 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. LoopsEach 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)
CapitalizationIn 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.
SpacingMuch of the older code lacks this. You will see stuff like this.
Which should be spaced in my opinion like so.
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/EchoingI've seen this a few times in code.
I feel that there's too many "breaks" in that string when it could all just be like this.
I also notice many times some inconsistencies when HTML is used.
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 |
| ||
Site Administrator
The Sorceress. Boing~ Level: 237 Posts: 3710/20774 EXP: 205703890 Next: 2275044 Since: 01-01-12 From: UK Last post: 1063 days Last view: 5 hours |
I can agree on the no brackets stuff.. but if it's just a single.variable.. why not go like
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 |
| ||
Developer
pancakes Level: 84 Posts: 285/1870 EXP: 5553301 Next: 108651 Since: 01-05-12 From: France Last post: 50 days Last view: 50 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:
results in the following query:
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 |
| ||
Normal User
Scryforce - A place that still exists. Neat. Level: 86 Posts: 52/2020 EXP: 6104815 Next: 37292 Since: 07-18-12 From: USA Last post: 994 days Last view: 976 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 |
Epele |
| ||
Site Administrator
The Sorceress. Boing~ Level: 237 Posts: 3714/20774 EXP: 205703890 Next: 2275044 Since: 01-01-12 From: UK Last post: 1063 days Last view: 5 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 |
| ||
Normal User
Scryforce - A place that still exists. Neat. Level: 86 Posts: 53/2020 EXP: 6104815 Next: 37292 Since: 07-18-12 From: USA Last post: 994 days Last view: 976 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 |
| ||
Developer
pancakes Level: 84 Posts: 286/1870 EXP: 5553301 Next: 108651 Since: 01-05-12 From: France Last post: 50 days Last view: 50 days |
Scrydan |
| ||
Normal User
Scryforce - A place that still exists. Neat. Level: 86 Posts: 54/2020 EXP: 6104815 Next: 37292 Since: 07-18-12 From: USA Last post: 994 days Last view: 976 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 |
| ||
Site Administrator
11 Hit Combo: Mother's Rosario Level: 109 Posts: 862/3393 EXP: 13581066 Next: 378579 Since: 12-30-11 From: Akron, Ohio; USA Last post: 126 days Last view: 1 day |
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 |
| ||
Developer
pancakes Level: 84 Posts: 288/1870 EXP: 5553301 Next: 108651 Since: 01-05-12 From: France Last post: 50 days Last view: 50 days |
Scrydan |
| ||
Normal User
Scryforce - A place that still exists. Neat. Level: 86 Posts: 80/2020 EXP: 6104815 Next: 37292 Since: 07-18-12 From: USA Last post: 994 days Last view: 976 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 |
| ||
Normal User
Scryforce - A place that still exists. Neat. Level: 86 Posts: 124/2020 EXP: 6104815 Next: 37292 Since: 07-18-12 From: USA Last post: 994 days Last view: 976 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 |
| ||
Site Administrator
11 Hit Combo: Mother's Rosario Level: 109 Posts: 910/3393 EXP: 13581066 Next: 378579 Since: 12-30-11 From: Akron, Ohio; USA Last post: 126 days Last view: 1 day |
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 |
| ||
Normal User
Scryforce - A place that still exists. Neat. Level: 86 Posts: 251/2020 EXP: 6104815 Next: 37292 Since: 07-18-12 From: USA Last post: 994 days Last view: 976 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 |
| ||
Site Administrator
11 Hit Combo: Mother's Rosario Level: 109 Posts: 1003/3393 EXP: 13581066 Next: 378579 Since: 12-30-11 From: Akron, Ohio; USA Last post: 126 days Last view: 1 day |
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 |
| ||
Developer
pancakes Level: 84 Posts: 293/1870 EXP: 5553301 Next: 108651 Since: 01-05-12 From: France Last post: 50 days Last view: 50 days |
Scrydan |
| ||
Normal User
Scryforce - A place that still exists. Neat. Level: 86 Posts: 259/2020 EXP: 6104815 Next: 37292 Since: 07-18-12 From: USA Last post: 994 days Last view: 976 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 |
| ||
Site Administrator
11 Hit Combo: Mother's Rosario Level: 109 Posts: 1011/3393 EXP: 13581066 Next: 378579 Since: 12-30-11 From: Akron, Ohio; USA Last post: 126 days Last view: 1 day |
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 |
| ||
Normal User
Scryforce - A place that still exists. Neat. Level: 86 Posts: 261/2020 EXP: 6104815 Next: 37292 Since: 07-18-12 From: USA Last post: 994 days Last view: 976 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. Edit: Someone also work on an error function and I'll begin to replace those as well. |
Main - AcmlmBoard Developer Zone - Board code stylization (PHP and MySQL) |
Acmlmboard v2.5.6 (06/11/2024) © 2005-2024 Acmlm, Emuz, et al. |
MySQL - queries: 211, rows: 632/665, time: 0.067 seconds. |