- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Actually no:
is wrong, because it should be:#
Admin
Maybe my ignorance is showing, but I can't figure out why you state (twice) that only ten results are coming back in the assignment to "pages". I've googled Episerver's GetContentResult() method and found no mention of any default limit, and there's certainly nothing in this horrible code that limits that result, so what am I missing?
Admin
In this case, that detail was provided by the submitter- I assume there's a configuration somewhere in their environment.
Admin
No. Bad programmer. The only proper way to start a scope is by placing the curly brace on a NEW LINE. What you are writing is Java.
Admin
Kernighan and Ritchie would like a word.
Admin
Another WTF is having a property that fetches data from the network. A property should be fast, and it's not the case here. It should be a method, preferably asynchronous
Admin
public int YourStatementIsNotAbsolute { get; set; }
Admin
Pretty damned important detail --- that code reads as if most of the table is being returned
Admin
Hold on, if the requirement is get most recent 5 published articles, why do you need elastic search at all? Why not just query the data source directly? Like SELECT TOP 5 Title, Contents, Date FROM Article WHERE NewsType = 'bla' AND Published = 1 ORDER BY Date DESC; if it's a SQL database.
Admin
I love the "JsonIgnore" attribute. At some point, they tried serializing an instance of the class which contains this property, (WHY??!!!!) and serialization either took a long time or failed altogether, and somebody must have debugged it and realized, oh wait, this property is doing a data retrieval operation.
Admin
Some people get paid by lines of code, some get paid by "done well".
Admin
It's not about how many lines you write, it's the readability. I always find it extremely annoying to read code with opening curly brace on the same line because it's difficult to match it to the closing brace. Consistency is king.
Addendum 2021-07-28 08:54: Also, methods have their opening brace on new line anyway; why introduce a different style to control blocks for the sake of making code more sense and harder to read? It's an all around bad practice.
Addendum 2021-07-28 08:54: Dense not sense
Admin
Same here. The point is the make sure your visual scope matches your code. So if you have a very short statment like a { get; set; } or an IF that has a very short outcome like say IF( condition) { var = value } or something similar where it all fits in one line than yes, keep it in one line.
Is just stupid and visual clutter.
But equally, if your code does have to break lines anyway than push that opening brace down as well so as to create a visual block that one can skim over or into easily with ones eyes without thinking about it.
Admin
Also, the people who wrote Golang, because it is literally impossible to write code that starts brackets on new lines in that language.
Admin
Agreed, a property accessor that's more than a line or three is a serious code smell. If you must do all that work in an accessor, at least use a lazy-loading pattern:
Bonus - you don't have to worry about where the brackets go :P
Admin
The question I have is how did someone become a senior architect and write such poorly "architected" idiocy. Sadly most architects I have known never write code at all and this is the end result. I suppose someone has to the tail on the bell curve.
Admin
How many architects do you know are skilled at bricklaying? Same story here.
Admin
Not knowing how this particular thing works, I certainly hope that the LINQ of the first search doesn't send an SQL query to get every article from the database, then remove things from those results. Because we know how code monkeys love to do that.
Admin
Probably because Elasticsearch IS the data source.
I hate it, but I have to admit it does make sense (having been in this situation before). If it's things like news articles, it makes sense to stuff them in Elasticsearch because it gives you easy access to things like fulltext search. Actually, it's probably 90% about the fulltext search ability. (It's not being used here but I would bet real money it's being used heavily elsewhere.)
It's annoying, but it does make sense.
Admin
Thanks for the crash course in C# / ElasticSearch.
Possibly a WTF is serving out the latest 5 news articles of a news type (genre?), which seems to spit in the face of all the proven content recommendation algo's. Are you trying to cultivate news addicts here or just share the news??!
Admin
Is no one even going to bother mentioning validating 'this.NewsType' after doing the query?
Admin
A common understanding is that if you encounter a closing }, you already know that it was caused by an opening {. You are not primarily interested in finding the matching {, but instead need to know what introduced that {, and therefore, you expect it at the same column as the closing }. The code that is depending on the construct is indented properly, so you can easily spot it, and also understand it as some kind of "encapsulated unit". This of course only works if you have consistent indentation, and it doesn't really matter if that is a fixed amount of spaces or actual tabs (which can be displayed as any amount of spaces the programmer desires, so that can be an advantage to change "indentation density", even in some of the simplest editors in case no real editor or IDE should be at hand). On the other hand, if you use a { on a separate line directly below the construct that caused it, you can achieve the same result just with one additional "visual vertical hop". Depending on the editor or IDE in use, selecting a } can quickly show you the corresponding { line, or lines. Languages like Python abandon the "block maker" { ... } altogether and require the programmer to use indentation for that purpose: defective indentation changes program structure, whereas the placement of { and } as well as the kind of indentation in C-like languages does not - overall it is just a cosmetic discussion.
Admin
Writing an ES search query is hard as fuck, the dev probably gave up and said fuck it Linq will optimise it for me anyway.
Admin
Personally I'd use a proper IF structure for that. Your version does not lend it self too well to debugging either via a debugger or via log statments. And yes, we do still use logs for debugging. that's just the price of working with proprietary hardware.
Admin
Ah, but how long will that word be?
Admin
As long as 10 articles are displayed, it will be tough for the testers!
Admin
I think this wrote someone who actually has not experience in C# at all, because any more seasoned .net developer knows that properties should behave like fields and not like methods, so no unpredictable and long run times, no side effects (thanks god at least that one isn't there) and especially no dependency outside of the scope of the class;so holy, relying even on something that isn't located on the machine is a big no-go and beyond bad practice for a property.
Secondly, it's elastic, so this code can't be that old. Why is it not async? It is also bad practice to use hardware resources synchronously except in few very specific cases. That point alone makes it clear that this code should never ever be in an property; because of the good practice rules above it is instantly clear that asynchronous properties make no sense :-)
Admin
This is incorrect.
C# has actually a style guide since .net 1.0 which was only adjusted in minor ways when it comes to formatting and naming conventions over time (specifically private member fields ... originally they followed the convention m_<name>, these days some people prefer either this or simply _ as prefix, which is IMO the more readable option, even tho it doesn't align with the more Java focused clean code book recommendation).
The correct c# bracket formatting is either: internal void LongMethod() { // Long method // }
or
private sealed override async Task<T> ShortMethodAsync<T>(CancellationToken cancellation = CancellationToken.None) { // Short statement // }
But in the later case Lambda notation is preferable anyway.
Brackets therefore are always on the same spacing level, no confusing mismatches and guessing which closing bracket belongs to which closing bracket, just clean visual scoping - which is for example completely different from C/C++ or Java which have a more chaotic approach with brackets following the previous scope line.
Admin
Apparently, either you're claiming that all braces and function bodies should be on the same line, or you're failing to write code fragments
Admin
To be fair, this comment system is a minor WTF, because it gives absolutely zero indication of what syntax can be used. In the absence of any indication, assuming verbatim plain-text is reasonable. Especially, since there is no preview option (live or otherwise).
Addendum 2021-07-31 15:49: Please add a "how to format" link :(
Admin
Python: Hold my beer.
I have yet to find any recommendation how to handle lengthier conditions, that does not result in making the code structure hard to see. For that matter, Python's "indentation as blocks" sometimes makes the code structure often unnecessarily hard to see to begin with, especially for code with complicated nesting structures.
In that regard, curiously, unix scripts are nice.
Curiously, Fortran of all things almost has that in the language, but makes the worst of it, by requires the THEN to be part of the same line.
At which point I can do
but trying to trick the language is awkward, will likely improve the readability only for myself, and has a good chance of confusing some editors auto-indent feature.
As for brace'd languages? Personally I prefer the terse
but in the case of block-head clauses with more than one line, I'd rather have
... ... no, still confusing.
Admin
Kernighan and Ritchie are wrong. Eric Allman would like a word.