How to make Databinding type safe and support refactoring?

Note this answer uses WinForm and was written before C# had ‘NameOf()’ Thanks to Oliver for getting me started I now have a solution that both supports refactoring and is type safe. It also let me implement INotifyPropertyChanged so it copes with properties being renamed. It’s usage looks like: checkBoxCanEdit.Bind(c => c.Checked, person, p => … Read more

Detecting superfluous #includes in C/C++?

Google’s cppclean (links to: download, documentation) can find several categories of C++ problems, and it can now find superfluous #includes. There’s also a Clang-based tool, include-what-you-use, that can do this. include-what-you-use can even suggest forward declarations (so you don’t have to #include so much) and optionally clean up your #includes for you. Current versions of … Read more

Refactor this code snippet [closed]

The common part with list and map working can be moved out from if/else: Map<String, MyObject> hashMap = new HashMap<>(); List<Value> listOfvalues; if (!hashMap.containsKey(key)) { listOfvalues = new ArrayList<>(); } else { listOfvalues = hashMap.get(key).getvalues(); log.info(String.format(“Duplicate key: %s. Previous Value(s): %s”, key, listOfvalues)); } listOfvalues.add(Value.builder().withValue1(Value1).withValue2(Value2).build()); hashMap.put(key, MyObject.builder().withkey(key).withvalues(listOfvalues).build());