Cute Builders And Developers

0 views
Skip to first unread message

Lynn Hepler

unread,
Aug 4, 2024, 7:45:38 PM8/4/24
to leubrenluchor
TheC++ and the Java API are supposed to be doing the same thing, so I'm wondering why they didn't use builders in C++ as well. Are there language reasons behind that, i.e. it's not idiomatic or it's frowned upon in C++? Or probably just the personal preference of the person who wrote the C++ version of Protocol Buffers?

It may be because there are a number of ways to tackle the same underlying problem. Usually, the problem being solved here is that of named arguments (or rather their lack of). An arguably more C++-like solution to this problem might be Boost's Parameter library.


One thing you failed to note in your question is that the Java classes emitted by protoc are immutable and thus must have constructors with (potentially) very long argument lists and no setter methods. The immutable pattern is used commonly in Java to avoid complexity related to multi-threading (at the expense of performance) and the builder pattern is used to avoid the pain of squinting at large constructor invocations and needing to have all the values available at the same point in the code.


The C++ classes emitted by protoc are not immutable and are designed so that the objects can be reused over multiple message receptions (see the "Optimization Tips" section on the C++ Basics Page); they are thus harder and more dangerous to use, but more efficient.


It is certainly the case that the two implementations could have been written in the same style, but the developers seemed to feel that ease of use was more important for Java and performance was more important for C++, perhaps mirroring the usage patterns for these languages at Google.


Your claim that "the C++ and the Java API are supposed to be doing the same thing" is unfounded. They're not documented to do the same things. Each output language can create a different interpretation of the structure described in the .proto file. The advantage of that is that what you get in each language is idiomatic for that language. It minimizes the feeling that you're, say, "writing Java in C++." That would definitely be how I'd feel if there were a separate builder class for each message class.


The Python output is different still. The class generated will include a field that you can manipulate directly. I expect the plug-ins for C, Haskell, and Ruby are also quite different. As long as they can all represent a structure that can be translated to equivalent bits on the wire, they're done their jobs. Remember these are "protocol buffers," not "API buffers."


The source for the C++ plug-in is provided with the protoc distribution. If you want to change the return type for the set_foo function, you're welcome to do so. I normally avoid responses that amount to, "It's open source, so anyone can modify it" because it's not usually helpful to recommend that someone learn an entirely new project well enough to make major changes just to solve a problem. However, I don't expect it would be very hard in this case. The hardest part would be finding the section of code that generates setters for fields. Once you find that, making the change you need will probably be straightforward. Change the return type, and add a return *this statement to the end of the generated code. You should then be able to write code in the style given in Hrnt's answer.


In C++ you have to explicitly manage memory, which would probably make the idiom more painful to use - either build() has to call the destructor for the builder, or else you have to keep it around to delete it after constructing the Person object.Either is a little scary to me.


It's that time of year when industry-leading companies and eager young start-ups come together to showcase their latest inventions and smartest technology. So if you're curious about what home innovation trends were on display at this year's Consumer Electronics Show (CES) and the International Builders' Show, Lennox recaps the tech that could be in your home!


Alexa, Amazon's AI voice-activated assistant and home automation hub, continues to have a strong presence in the smart home arena. Building on the success of its Alexa-enabled Echo and Echo Dot devices, Amazon has opened up its voice-command technology so that it can now be integrated into millions of other products.


From Alexa-enabled fridges and ovens to Ford and Volkswagen cars, Alexa is the dominant presence in the world of voice command. In fact, the popularity of voice control is on the rise, especially in the home environment, where voice commands are thought to deliver a much better user experience than tapping an app on a smartphone.


No fewer than five robotic helpers debuted at CES 2017, from the Alexa-enabled Aristotle, a smart baby monitor, to the $30,000 Ewaybot, an indoor/outdoor robot that comes complete with hands. And not forgetting LG's Hub bot, which functions as a smart-home hub and works specifically with LG appliances, and the adorable Kuri, which is both cute and practical. All these helpful robots are designed to make home life better, safer, smarter and more connected, plus they don't shed, have accidents on the carpet, or bring home dead mice.


Kitchens always seem to inspire the greatest range of smart home products, and appliances introduced in 2017 are no exception. LG debuted its new Smart Insta View Refrigerator, which is fully Alexa-enabled and allows the homeowner to order groceries, or play music, just by talking to it.


Samsung premiered its mammoth four-in-one FlexWash + FlexDry system which lets you do two loads at once. LG had the same idea with their Twin Wash system, and also presented the LG Styler, a closet-like contraption that refreshes clothes and comes at $2,000 a pop. Whirlpool, meanwhile, is adding limited Alexa capability to its new washers, letting you check on the time left for a load using an Alexa-enabled device nearby.


As the in-home Internet of Things continues to expand, so Wi-Fi security concerns continue to grow for homeowners and product developers alike. BitDefender, Intel and Symantec all announced router systems, or partnerships, at CES designed to beat hackers trying to access homeowner networks.


Another home network protection option is Cujo. The compact device plugs into the home network via a network cable. It automatically breaks down local and Internet traffic, and sends statistics on that data to the cloud for further analysis. If a threat or suspicious activity is detected, Cujo will block it and inform users via a mobile app.


The products and ideas debuted at CES and the International Builders' Show keep pushing and expanding the boundaries of technology and innovation. At Lennox, we also strive to create innovative products that make our customers' homes more connected, efficient and comfortable.


Velo Facades offers an innovative high-performance rainscreen solution that aligns perfectly with the new measures proposed in the 2025 NCC update. These facades excel in energy efficiency, thanks to superior thermal insulation, which will help meet the tighter energy efficiency requirements.


By incorporating Velo Facades into your projects, builders and developers can save valuable time and resources while ensuring you comply with these new proposed standards of the NCC, for sustainable, high-performing, and durable buildings.

3a8082e126
Reply all
Reply to author
Forward
0 new messages