39
votes
Accepted
How to represent a set in JSON?
Well, you can't. As you said, you can represent arrays and dictionaries. You have two choices.
Represent the set as an array. Advantage: Converting from set to array and back is usually easy. ...
35
votes
What's the use case for formatting monetary values with a *system-dependent* currency symbol?
Is there a use-case for build-in currency formatting?
Basically, with currencies you have two ways of working:
in a currency-aware environment, where people register amount sometimes in local and ...
29
votes
One-liners vs. readability: when to stop reducing code?
No matter what code you write, readable is best. Short is second best. And readable usually means short enough so you can make sense of the code, well named identifiers, and adhering to the common ...
16
votes
One-liners vs. readability: when to stop reducing code?
I don't think you will get a better answer than "use your best judgement". In short you should strive for clarity rather than shortness. Often, the shortest code is also the clearest, but if you focus ...
13
votes
What's the use case for formatting monetary values with a *system-dependent* currency symbol?
You are absolutely right, formatting using a system-dependent currency symbol is dangerous. I actually knew people who lost lots of money through that. Especially with US dollar and Euro being close ...
12
votes
How to represent a set in JSON?
Don't try to represent sets in JSON. Do it when parsing the data instead.
Your JSON data should have a schema which specifies which fields should be treated as a set, or you may have a metadata ...
11
votes
What's the use case for formatting monetary values with a *system-dependent* currency symbol?
The question seem to be "why programming languages, frameworks and operating systems support features that are not the best practices for professional developers in large multinational ...
8
votes
What's the use case for formatting monetary values with a *system-dependent* currency symbol?
There are a lot of long answers to a simple question here. You ask for a use-case and there's a simple one that I don't think has been mentioned yet: games.
If a game involving money is set in an ...
7
votes
One-liners vs. readability: when to stop reducing code?
Part of the problem here is "what is readibility". For me, I look at your first code example:
def name(use_email = true)
# If firstname and surname are both blank (empty string or undefined)
# and ...
7
votes
What's the use case for formatting monetary values with a *system-dependent* currency symbol?
Thirty years ago or more it was probably still reasonable to assume that most computer systems that dealt with financial amounts, did so exclusively in the local currency.
In the English-speaking ...
6
votes
Why not program our video text terminals/terminal emulators to use something JSON or XML on the backend instead of ANSI escape sequences?
Your question is sort of like saying assembly is difficult to work with, so computers should use higher level languages instead. The ANSI format is the right level of abstraction for working with ...
6
votes
Accepted
What happen to string.ToCommonSenseCase()?
That's called sentence case, and there are some challenges with it:
The word "I" needs to be capitalized, wherever it appears in the sentence. Granted, the programming language could detect that.
...
5
votes
What's the use case for formatting monetary values with a *system-dependent* currency symbol?
TL;DR
Currency formatting has been an OS-level configuration for decades now, and the pre-internet days were a very different beast in terms of the frequency of international transactions and the need ...
4
votes
Accepted
Why not program our video text terminals/terminal emulators to use something JSON or XML on the backend instead of ANSI escape sequences?
There is a simple reason. When you are typing you can only input a character at a time.
Something that is processing typed text has to deal with what in effect is invalid markup, half a json blob or ...
2
votes
Custom object formatting caveats as to not confuse end users
As cool as making custom formatting directives are is there some sort of mantra I should try to follow where I can try and keeps things simple initially while not hiding or confusing users about where ...
Community wiki
2
votes
One-liners vs. readability: when to stop reducing code?
This is probably a question where it's hard not to give an opinion-based answer, but, here are my two cents.
If you find that making the code shorter doesn't impact readability, or even improves it, ...
2
votes
Accepted
Clean code: formatting rules, dependent functions, multiple calls
TL;DR - Whatever is more readable.
I Sometimes:
Order methods based on the order of execution.
Group similar methods (on different types together).
Create groups of methods that act on the same type.
...
1
vote
Accepted
deciding where to put "formatting" logic - database or in application layer
I don't think this is a formatting question but a domain question.
Your database needs to hold and model data appropriate to your business domain (disregarding the staging of sources).
It's hard to ...
1
vote
One-liners vs. readability: when to stop reducing code?
The answer is a bit subjective, but you have to ask yourself with all the honesty you can muster, if you would be able to understand that code when you come back to it in a month or two.
Each change ...
1
vote
Abstract composition hierarchy with multiple implementations
Essentially you want to serialize/deserialize your model to/from a bunch of different formats. By model I'm referring to your 'logical hierarchy'.
Because every translator needs to be able to deal ...
1
vote
Where to format number strings? Server or browser?
Formatting should be done as late as possible.
Inside your application, you should represent data in a format that makes it easy to work with. E.g. you would probably represent numbers with a numeric ...
1
vote
Image resolution in a RESTful interface
Ok, you have a resource at /my/cat.
Let's assume a cat has a name and a color.
When you request:
GET /my/cat HTTP/1.1
Accepts: application/json
You get:
{
name: "Fluffy",
color: "black"
}
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
formatting × 32sql × 4
java × 2
database × 2
json × 2
xml × 2
strings × 2
syntax × 2
clean-architecture × 2
editor × 2
design × 1
c# × 1
design-patterns × 1
javascript × 1
rest × 1
.net × 1
database-design × 1
api × 1
coding-style × 1
open-source × 1
data-structures × 1
refactoring × 1
documentation × 1
language-agnostic × 1
coding-standards × 1