Skip to main content
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. ...
gnasher729's user avatar
  • 47.5k
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 ...
Christophe's user avatar
  • 80.6k
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 ...
Greg Burghardt's user avatar
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 ...
JacquesB's user avatar
  • 61k
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 ...
gnasher729's user avatar
  • 47.5k
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 ...
Lie Ryan's user avatar
  • 12.5k
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 ...
Alexei Levenkov's user avatar
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 ...
Kichi's user avatar
  • 89
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 ...
David Arno's user avatar
  • 39.5k
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 ...
Steve's user avatar
  • 11.7k
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 ...
Karl Bielefeldt's user avatar
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. ...
Glorfindel's user avatar
  • 3,157
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 ...
Flater's user avatar
  • 56.3k
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 ...
Ewan's user avatar
  • 79.8k
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 ...
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, ...
Filip Milovanović's user avatar
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. ...
DavidT's user avatar
  • 4,263
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 ...
LoztInSpace's user avatar
  • 1,209
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 ...
Berin Loritsch's user avatar
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 ...
doubleYou's user avatar
  • 2,847
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 ...
amon's user avatar
  • 135k
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" } ...
ku1ik's user avatar
  • 111

Only top scored, non community-wiki answers of a minimum length are eligible