4 ms·
For the camera example, I would rather do: Camera camera = createCamera({"rotation": 90}); If you need another camera with different parameters then creat
by choward 6y ago
For the camera example, I would rather do:
Camera camera = createCamera({"rotation": 90});
If you need another camera with different parameters then create a new one. You can build the options before the creating the cameras to avoid duplication.
Bitmap bitmap = createBitmap({data: data, samepleSize: 4});
ImageView imageView = createImageView(bitmap);
In the case where you are mutating image view, it's an optimization to reuse the same memory that could be handled by your language/framework so you don't have to think about it. For example, like with react it could create an internal representation of what is rendered and then diff it with the new rendering and reuse the internal representation of image view and mutate it for you so you don't have to think about doing the optimization yourself.
- NeutronStar 6y agoOr Camera camera = new Camera({"rotation": 90}); and Bitmap bitmap = new Bitmap({data: data, samepleSize: 4}); ImageView imageView = new ImageView(bitmap);
- teekert 6y agoAs a Python programmer, all I see is heaps of very similar and the same words. It looks like mess, I'm sorry.
- mmm_grayons 6y agoA Python background explains that, as y'all tend to worry less about memory usage and re-use. This can have its upsides, but it probably creates a bit of a blind spot here, because it's referencing the sort of thing one probably wouldn't do in python.
- jschwartzi 6y agoThat's because you're telling the compiler what the type of the variables is ahead of time so the compiler knows whether you're using the type correctly. As opposed to in Python constructing an object and adding functions to it one by one at run-time, and only checking that the type is used correctly when the type is used. There's a trade-off being made between conciseness on one hand and fast feedback on the other. Python leans toward conciseness and Java/C++ lean toward fast feedback. In Python you can express complicated ideas quickly, but you can't necessarily express correct ideas quickly. Whereas in C++ you can express correct ideas quickly but you can't express complicated ideas quickly. If it's costly for you to correct defects in deployed software then you might prefer the fast feedback of C++ or Java rather than the flexibility of Python.
- dheera 6y agoThat part is fine, but Java idioms seem to routinely think that String string = new String("string"); isn't enough repetition, and so they take it a step further: StringFactory mStringFactory = new StringFactory(StringFactory.FOO || StringFactory.BAR); StringOptions stringOptions = new StringOptions(); try { String string = mStringFactory.createString(StringFactory.STRING, "string", stringOptions); } catch (java.lang.string.StringException e) { runOnUIThread( new Runnable() { try { // facepalm I'm exaggerating ;) but as a Python programmer myself, this is what comes to my mind whenever someone says the word "Java" to me. Obviously not for strings, but for more advanced constructs (e.g. Bluetooth) I often do see this much repetition in Java code. It's almost like someone designed this language to prank engineers.
- arethuza 6y agoThat a reasonably parody of a lot of Java code - but I don't think it's really a property of Java the language but some odd principles that seem to be popular (or used to be popular) in the Java community. BTW You missed: public static final String STRING_STRING_CONSTANT = "string";
- teekert 6y agoThank this is a very nice answer and it makes sense to me. Indeed I once sat down to try Kotlin for a day. The amount of code I had to write to get a json from an api into a dict that I could address by key was baffling to me. In python it took met 2 imported modules and then 2 lines (something like some_dict = module.scrape_api() value_I_want = some_dict['my_value'] I gave up after a day, when I just wrote down exactly what I expected to pull down and what types were in the values and keys. I can understand it helps you prevent errors but man is there a learning curve... BTW, I could write those checks in Python as well, but they are optional.
- garethrowlands 6y ago> I could write those checks in Python as well, but they are optional You're probably going to need to check `value_I_want` though. So maybe the checks aren't quite as optional as they look.
- choward 6y agoI was just using the same type of typing syntax as the OP. I could have left that out.
- nomel 6y agoThat works until you want to let the user rotate the phone without interrupting the stream. And, creating a new camera probably means freeing the resources from the old camera, which, for some cameras, can mean power cycling. A rotation is a gravity based human concept that results in the transformation of stream data before being displayed, not anything related to the actual camera.
- deleted 6y ago[deleted]