[–] nametoremember 15y ago ↗ "And the second kind tests something that some other part of the system already knows. Let’s ban the second kind…"Can you give an example? [–] kevinrutherford 15y ago ↗ Imagine a method with this outline:File createFile(String name, boolean istemp) { if (istemp) // do temp stuff else // do regular file stuff }That's an 'if' statement that only exists as a response to the boolean parameter. We can remove the 'if' by having two methods instead:File createFile(String name) File createTempFile(String name)
[–] kevinrutherford 15y ago ↗ Imagine a method with this outline:File createFile(String name, boolean istemp) { if (istemp) // do temp stuff else // do regular file stuff }That's an 'if' statement that only exists as a response to the boolean parameter. We can remove the 'if' by having two methods instead:File createFile(String name) File createTempFile(String name)
3 comments
[ 3.4 ms ] story [ 25.5 ms ] threadCan you give an example?
File createFile(String name, boolean istemp) { if (istemp) // do temp stuff else // do regular file stuff }
That's an 'if' statement that only exists as a response to the boolean parameter. We can remove the 'if' by having two methods instead:
File createFile(String name) File createTempFile(String name)