Google for Developers’ Post

Embark on a journey into the heart of Dart programming. In our latest Dev Challenge, we delve into a perplexing piece of code that's defying the norms of Dart's access control and teetering on the edge of causing a potential crash. This isn't just a challenge; it's an invitation to sharpen your coding acumen, rethink strategies, and elevate your problem-solving skills. Whether you're a dev challenge aficionado or a Dart detective, your insights could be the key to untangling this riddle. Engage with us in the comments with your solutions and revelations. Let's refine this code to perfection. Ready to Flutter into action? Your coding journey to excellence starts here. Watch now and join the conversation!

Leonard Collins

Engineering Leadership | Android Development Expert | Flutter | System Design | Java Full Stack

9mo

Use assertions in the constructor to help prevent erroneous input, e.g. assert(appsInDevelopment >= 0), assert(appsPublished >= 0); since having appsInDevelopment = -1 would cause isDeveloper to fail for all values of appsPublished and a negative value doesn't ( or shouldn't ) have any meaning here. In plain language, isDeveloper is defined as having at least one published app or at least 1 app in development, I would suggest using syntax that clearly tells that story, e.g. appsPublished > 0 || appsInDevelopment > 0 String.length returns the number of codeUnits and that emoji requires 2, i.e. length == 6, adding  get usernameLength => username.runes.length;  would be a better representation of user expectations

DINESHKUMAR S

AWS | Cloud | Java Developer

9mo

isDeveloper getter: The current implementation of the isDeveloper getter seems to be incorrect. The bitwise OR operator (|) is used instead of the logical OR operator (||). This means that the condition appsPublished | appsInDevelopment > 0 is checking if the bitwise OR of appsPublished and appsInDevelopment is greater than zero, which might not always yield the correct result. Instead, you should use the logical OR operator (||) to correctly check if either appsPublished or appsInDevelopment is greater than zero. Username length: The code includes an assertion assert(dash.username.length == 5); to check if the username length is 5 characters. However, this assertion might fail if the username is not exactly 5 characters long.

Like
Reply
Shivam Kumar

Android Developer/Flutter Developer/Java Developer

9mo

Try this below code definitely worked class UserProfile { final String username; final int age; final int appsPublished; final int appsInDevelopment; const UserProfile({ required this.username, required this.age, required this.appsPublished, required this.appsInDevelopment, }); bool get isDeveloper => appsPublished > 0 || appsInDevelopment > 0; } void main() { const dash = UserProfile( username: 'Dash', age: 11, appsInDevelopment: 500, appsPublished: 2, ); print(dash.isDeveloper); assert(dash.username.length == 4); }

Like
Reply

Emoji usually takes an extra length i guess that's why it's a Bug there

Like
Reply
Gururaj H Desai

Cloud Support Associate Intern @AWS || Pursuing Master's in Information Technology || University of North Carolina at Charlotte || Siemens || AWS Certified 3x ||

9mo

This is a great 😊

Like
Reply
Ameer ALHAMAMI

Contact Center Representative في ايرثلنك للاتصالات

9mo

Thanks for your sharing%

Like
Reply
Amin Jafari

Senior Flutter developer | Collaborate 15+ Successful Projects | Co-founder of Successful Dev Team | 6.5 Years of Mobile App Mastery | Bloc, Google APIs, TDD | Android, IOS, Cross-Platform App

9mo

I love your explanation man

Like
Reply
Gabriel Costache

Software Engineer @TMH

9mo

Spaces matter :)

Like
Reply
See more comments

To view or add a comment, sign in

Explore topics