Hot answers tagged

10

Globals # TO-DO: GET RID OF GLOBAL STATE Yep. You seem to already understand this one. Having a reset betrays a place in your design that would be well-suited to an object that can be thrown away and re-constructed, which is usually a more useful model than existing state that can be reset. Moving on. Docstrings Rather than # parse_resp is the main function ...


6

Your speed-up claim: avoid loading the whole file at once, instead parsing a file line by line, which seems to be 2x as fast according to testing seems highly unlikely, and I would like to see proof of this. A compiled-and-tuned built-in JSON parser that operates on an in-memory buffer is nearly certain to outperform a non-compiled, non-built-in, line-by-...


3

Fundamentally, not really. When you need to create a nested structure, there are no built-in ways to get around explicitly testing if the intermediate object(s) exist, and creating them if they don't. (If you just wanted to access a possibly-existing nested element, you could use optional chaining to achieve it concisely, but nested creation is much more ...


3

Json.NET has a very useful JsonConverter which you can use to add a custom JsonConverter. Which what you actually need. So, you can do something like this : public class CandlestickConverter : JsonConverter { public override bool CanConvert(Type objectType) { return objectType == typeof(Candlestick); } public override object ReadJson(...


2

In Python, you don't need to create your variables before using them, so the address = '' before your loop is unnecessary. You also don't need to reset a variable before using it again, so the address = '' at the end of each loop iteration is particularly unnecessary. You currently get the addresses from the DB and then concatenate parts of that address as ...


2

Intent Reading only the code The code gives hints at some higher level use, but what that could be is unclear. I will use intent to fill the blanks Good code provides more than just an understanding of the logic, but conveys intent. The strongest guide to intent is naming, I find this more true for less experienced coders. Deducing intent From the naming map,...


2

TL;DR This code snippet is rather taken out of context and is likely symptomatic of bigger issues in the codebase as a whole. You may have bigger problems than trying to improve these few lines of object initialization. A few minor points... For starters: 'use strict'; Good start! let map = {}; Use const. Using let says "I'm going to re-assign this ...


1

A few quick observations: String extensions is generally a bad idea because string is such a common type. Conversion code can be written more defensively. Use TryParse instead of Parse and if TryParse fails then handle that by throwing an Exception, or some other error handling. Throwing a generic exception with no message is not great.


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