• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 04:48
CET 09:48
KST 17:48
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
Intel X Team Liquid Seoul event: Showmatches and Meet the Pros0[ASL20] Finals Preview: Arrival13TL.net Map Contest #21: Voting10[ASL20] Ro4 Preview: Descent11Team TLMC #5: Winners Announced!3
Community News
Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win42025 RSL Offline Finals Dates + Ticket Sales!9BSL21 Open Qualifiers Week & CONFIRM PARTICIPATION1Crank Gathers Season 2: SC II Pro Teams10Merivale 8 Open - LAN - Stellar Fest4
StarCraft 2
General
RotterdaM "Serral is the GOAT, and it's not close" DreamHack Open 2013 revealed Intel X Team Liquid Seoul event: Showmatches and Meet the Pros Chinese SC2 server to reopen; live all-star event in Hangzhou Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win
Tourneys
Merivale 8 Open - LAN - Stellar Fest Crank Gathers Season 2: SC II Pro Teams 2025 RSL Offline Finals Dates + Ticket Sales! $5,000+ WardiTV 2025 Championship $3,500 WardiTV Korean Royale S4
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 497 Battle Haredened Mutation # 496 Endless Infection Mutation # 495 Rest In Peace Mutation # 494 Unstable Environment
Brood War
General
Ladder Map Matchup Stats BW General Discussion BSL Team A vs Koreans - Sat-Sun 16:00 CET [ASL20] Ask the mapmakers — Drop your questions BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[ASL20] Grand Finals The Casual Games of the Week Thread BSL21 Open Qualifiers Week & CONFIRM PARTICIPATION ASL final tickets help
Strategy
How to stay on top of macro? PvZ map balance Soma's 9 hatch build from ASL Game 2 Current Meta
Other Games
General Games
Stormgate/Frost Giant Megathread General RTS Discussion Thread Path of Exile Nintendo Switch Thread Dawn of War IV
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread YouTube Thread The Chess Thread
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece Korean Music Discussion Series you have seen recently...
Sports
MLB/Baseball 2023 2024 - 2026 Football Thread Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023 NBA General Discussion
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
Analysis of the Trump-Lee S…
Peanutsc
Reality "theory" prov…
perfectspheres
The Benefits Of Limited Comm…
TrAiDoS
Our Last Hope in th…
KrillinFromwales
Certified Crazy
Hildegard
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1559 users

The Big Programming Thread - Page 926

Forum Index > General Forum
Post a Reply
Prev 1 924 925 926 927 928 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
TMG26
Profile Joined July 2012
Portugal2017 Posts
December 05 2017 20:34 GMT
#18501
On December 05 2017 12:24 WarSame wrote:
Show nested quote +
On December 04 2017 15:17 Blisse wrote:
Use a dependency injection framework and keep the Account object alive as long as the user is logged in.

I've been reading about dependency injection for the last little bit and I fail to see how it lets me implement a session any differently than just creating a regular object would. Could you clarify that?


It simplifies creating and passing objects around.
For example in spring you can just say you need an Accaunt objected, and if there is one bean of that it will automatically get there.
The initial idea was to have everything in interfaces so you could inject the preferred implementation which would also help with testing. And you would just let the dependency injection framework create and passed the actual object.

I don't know if you can use spring in Android, because I only did a single small app once. But your case is simple, (assuming annotation config) in the classes you need the account, just declare it as an instace variable and annotate with @Autowired. Then you just need to provide the creation mechanism. If you Account has an empty constructor (or every dependency can be autowired) you can just anotate the class with @component, otherwise you have to provide a method annotated with @bean responsible to create it.
This is a monky patch. It's full of crap because I don't know your application. Don't do what I said, instead understand how it works with this example.
You should check out the scope of the object, and if you are using DI it's probably better to organize everything with it. Think about what should be a bean what should not. Take good care of dependency stuff.
Some people will claim that field injection in java is shit. The reason are only historic and being weird having something setting a private field. With mordern test frameworks the only real reaon against field injection is that it's easier to detect that you have too many dependencies using constructor injection.
Supporter of the situational Blink Dagger on Storm.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
December 05 2017 23:25 GMT
#18502
On December 06 2017 04:18 Blisse wrote:
Show nested quote +
On December 05 2017 12:24 WarSame wrote:
On December 04 2017 15:17 Blisse wrote:
Use a dependency injection framework and keep the Account object alive as long as the user is logged in.

I've been reading about dependency injection for the last little bit and I fail to see how it lets me implement a session any differently than just creating a regular object would. Could you clarify that?


Are you unsure about dependency injection or dependency injection as it relates to scoping?




Just got this Google coding challenge terminal thing in the browser, it's weird.

More unsure of how dependency injection works as a framework. I understand at its basis DI is just passing an object you depend on in, instead of directly depending on it. I suppose knowing how it works as a framework is the real challenge.

On December 06 2017 05:34 TMG26 wrote:
Show nested quote +
On December 05 2017 12:24 WarSame wrote:
On December 04 2017 15:17 Blisse wrote:
Use a dependency injection framework and keep the Account object alive as long as the user is logged in.

I've been reading about dependency injection for the last little bit and I fail to see how it lets me implement a session any differently than just creating a regular object would. Could you clarify that?


It simplifies creating and passing objects around.
For example in spring you can just say you need an Accaunt objected, and if there is one bean of that it will automatically get there.
The initial idea was to have everything in interfaces so you could inject the preferred implementation which would also help with testing. And you would just let the dependency injection framework create and passed the actual object.

I don't know if you can use spring in Android, because I only did a single small app once. But your case is simple, (assuming annotation config) in the classes you need the account, just declare it as an instace variable and annotate with @Autowired. Then you just need to provide the creation mechanism. If you Account has an empty constructor (or every dependency can be autowired) you can just anotate the class with @component, otherwise you have to provide a method annotated with @bean responsible to create it.
This is a monky patch. It's full of crap because I don't know your application. Don't do what I said, instead understand how it works with this example.
You should check out the scope of the object, and if you are using DI it's probably better to organize everything with it. Think about what should be a bean what should not. Take good care of dependency stuff.
Some people will claim that field injection in java is shit. The reason are only historic and being weird having something setting a private field. With mordern test frameworks the only real reaon against field injection is that it's easier to detect that you have too many dependencies using constructor injection.

Thanks for the info. I know you can't use Spring on Android because you can't use Beans(for some reason).
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
TMG26
Profile Joined July 2012
Portugal2017 Posts
December 05 2017 23:39 GMT
#18503
A quick google search gave GUICE as a DI framework for android.

But you rarely should need the same global state everywhere. Try to see if you can isolate classes from that dependency.

And I sugest everyone to read Build Maintainable Software by the SIG guys.
It's a pretty entry level and straight foward book but is well written, straight to the point and points out opposite views. And applies to pretty much any project. By following that book rulea you eventually end up following more complex ones by intuition.
10 extremely simple rules! All you need.
Supporter of the situational Blink Dagger on Storm.
shz
Profile Blog Joined October 2010
Germany2687 Posts
December 06 2017 01:07 GMT
#18504
I think you use Dagger 2 for DI on Android.
Liquipedia
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
December 06 2017 04:38 GMT
#18505
Dagger 2 and GUICE were the main recommendations I read elsewhere, so thank you for giving more strength to those recommendations.

I'm finding it very hard to understand Patterns and concepts like DI. I understand that they make your code more flexible and maintainable. I've worked maintenance at a bank for the last 1.5 years so I understand why that's important. I find it hard to relate what these cerebral concepts are supposed to accomplish to concrete improvements in my code. Is it something you need to be on the maintaining end of to understand fully?
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
TMG26
Profile Joined July 2012
Portugal2017 Posts
December 06 2017 08:51 GMT
#18506
No.
DI is actuctually pretty simple to understand. You specify how to create objects and their scope, and the framework will create them for you. And them you don't need to pass them around, you can just use an inject/autowire annotation and the framework does it for you. With this you no longer need to have code to instanciate your objects, DI framewok will find and create the objects you need. Suddendly spotting the 'new' keyword in your code gets rare.
In web Backends it makes your LOCs go down a lot. And if you use interfaces you can easily switch objects that you are injecting. Most frameworks also support naming objects/beans if you need more than one object of!a kind alive and the type system is not enough.

A simple DI framework with just the basic features is very simple to implement, with either the old system of a xml file to inject stuff, or the more recent java annotations ones. But big frameworks like spring have lots of stuff like injecting private fields and have a huge amount of configurations.
Supporter of the situational Blink Dagger on Storm.
shz
Profile Blog Joined October 2010
Germany2687 Posts
December 06 2017 13:21 GMT
#18507
On December 06 2017 13:38 WarSame wrote:
Dagger 2 and GUICE were the main recommendations I read elsewhere, so thank you for giving more strength to those recommendations.

I'm finding it very hard to understand Patterns and concepts like DI. I understand that they make your code more flexible and maintainable. I've worked maintenance at a bank for the last 1.5 years so I understand why that's important. I find it hard to relate what these cerebral concepts are supposed to accomplish to concrete improvements in my code. Is it something you need to be on the maintaining end of to understand fully?


Maybe this helps. I don't think it matters that the examples are in JS.

Liquipedia
phar
Profile Joined August 2011
United States1080 Posts
Last Edited: 2017-12-06 17:04:03
December 06 2017 16:34 GMT
#18508
On December 06 2017 04:18 Blisse wrote:

Just got this Google coding challenge terminal thing in the browser, it's weird.

If that's like while doing a Google search, it can result in a job.

Or at least a job interview.
Who after all is today speaking about the destruction of the Armenians?
Acrofales
Profile Joined August 2010
Spain18102 Posts
December 06 2017 17:22 GMT
#18509
On December 04 2017 13:55 WarSame wrote:
That video is pretty good.

Say I have a class in Android, Account, instanced to represent the current user's account. This shows up everywhere. I could pass it through Intents. I could put it in a subclassed Application. I could used Shared Preferences. If we assume that just about every activity will need it what is the best approach?

This was the original question. It seems pretty simple. I'm not quite sure why you'd want to load what seems to be quite a heavy framework to solve something as simple as passing around an Account object. Especially as the problem isn't with dependency boondoggles, it's specifically about accounts in Android. And the Android framework already provides the AccountManager to deal with that.

What exactly you need the account for is a more interesting question. If all you want is to get locally stored user data, there are better solutions. If it's to sync to some clould service, you definitely want to use the Android account manager, and probably a SyncAdapter.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
December 06 2017 19:56 GMT
#18510
On December 07 2017 01:34 phar wrote:
Show nested quote +
On December 06 2017 04:18 Blisse wrote:

Just got this Google coding challenge terminal thing in the browser, it's weird.

If that's like while doing a Google search, it can result in a job.

Or at least a job interview.


I've already been flown out and interviewed and rejected by Google, twice :cries:

My excuse is, I didn't want to work there anyways!
There is no one like you in the universe.
Excludos
Profile Blog Joined April 2010
Norway8141 Posts
December 06 2017 20:35 GMT
#18511
On December 07 2017 04:56 Blisse wrote:
Show nested quote +
On December 07 2017 01:34 phar wrote:
On December 06 2017 04:18 Blisse wrote:

Just got this Google coding challenge terminal thing in the browser, it's weird.

If that's like while doing a Google search, it can result in a job.

Or at least a job interview.


I've already been flown out and interviewed and rejected by Google, twice :cries:

My excuse is, I didn't want to work there anyways!


"Hahaha ;D;D you thought I wanted 2 work there? ur so stupid I was just folling round no one wants a shit job leik that you cuck I hope the company is run over by a car!" *secretly cries inside*
sc-darkness
Profile Joined August 2017
856 Posts
Last Edited: 2017-12-06 23:51:25
December 06 2017 23:48 GMT
#18512
I'm sure you know this, but I've just followed a pseudo-code algorithm for quicksort (it's almost copy/paste). It took 11 seconds to populate a vector with 1,000,000 numbers and to sort it in debug. How about std::sort? 3 seconds. So, just use your library's algorithms. I've only done this to see to check quicksort algorithm though.

That said, I didn't use the same vector but I don't doubt std::sort is faster anyway.

Edit: Both are < 1 sec in release.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
December 07 2017 00:39 GMT
#18513
What do you mean by "release"?

Also, what quicksort did you use? The most basic, or a variant?

I don't know what language that is, but some languages it's really really hard to beat the standard sort algorithm. It may be the case that your standard sort changes approach based on the circumstances.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
Last Edited: 2017-12-07 03:59:33
December 07 2017 01:40 GMT
#18514
On December 07 2017 02:22 Acrofales wrote:
Show nested quote +
On December 04 2017 13:55 WarSame wrote:
That video is pretty good.

Say I have a class in Android, Account, instanced to represent the current user's account. This shows up everywhere. I could pass it through Intents. I could put it in a subclassed Application. I could used Shared Preferences. If we assume that just about every activity will need it what is the best approach?

This was the original question. It seems pretty simple. I'm not quite sure why you'd want to load what seems to be quite a heavy framework to solve something as simple as passing around an Account object. Especially as the problem isn't with dependency boondoggles, it's specifically about accounts in Android. And the Android framework already provides the AccountManager to deal with that.

What exactly you need the account for is a more interesting question. If all you want is to get locally stored user data, there are better solutions. If it's to sync to some clould service, you definitely want to use the Android account manager, and probably a SyncAdapter.

Yes, it is a local account. It doesn't sound like AccountManager is what I want. For now I've just stuffed it into a Session static variable. After I get to a place where I'm happy with my project I'll post the github link and ask for feedback. There are a few specific sections of my app that I think are weak and I'm hungry to improve my coding.

Thank you to everyone who provided feedback.
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
Neshapotamus
Profile Blog Joined May 2006
United States163 Posts
December 07 2017 06:10 GMT
#18515
I can't believe all the bad advice I'm hearing.

First and foremost. Stop using dependency injection with inversion of control. It's just a bad idea for a cluster fuck. While people state all the "advantages" of dependency injection, they don't state the disadvantages.

Here are great reasons not to use it:
1) If you are using a compiled time program, - Why go from a compile time error to a runtime error? You aren't able to reason about the behavior of your program.

2) How many times have you really switched out an implementation of an object? I am being serious. How many times?

3) It creates bad code - I want a dependency, let me see, someone created this object for me that will have a part of what I need. Let me just bring in their dependency and all their extra garbage with it. Remember, you are not going to be the person looking at this code in the future and modifying it, so any methods and objects are fair game to be misused.

4) Object construction is actually necessary to write elegant code. Just because you can make something into an object doesn't mean it should be an object.

5) Dependency Injection Magic - Significant amount of the times, people spend time figuring out the nuances of the DI framework instead of their actual code.

What you should learn instead.
1. Data structures
2. Algorithms
3. Functional Programming

As someone has stated. Dependency Injection with IoC is just a simple idea. It is a class that has a HashMap with a simple interface, provide it a key, you get back a value. To construct the value, the value needs to know about all its dependencies. This means every object is a vertex and the edges represent a dependency. This really means that you have a Directed Acyclical Graph (DAG). To create an object, you just have to topologically sort the DAG and create the objects in order to initialize your intended object.

If you feel like this idea is valuable to you, use it, otherwise, don't use it.

Second, you should know about all the fundamental sorting algorithms and how they work if you want to be a serious programmer. You should also learn the idiosyncrasies of the sorting library that is given by the framework. It is detrimental to think you should only use the framework when other steps can be taken to speed up your specific goal.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2017-12-07 09:24:35
December 07 2017 07:25 GMT
#18516
On December 07 2017 15:10 Neshapotamus wrote:
I can't believe all the bad advice I'm hearing.

First and foremost. Stop using dependency injection with inversion of control. It's just a bad idea for a cluster fuck. While people state all the "advantages" of dependency injection, they don't state the disadvantages.

Here are great reasons not to use it:


1) If you are using a compiled time program, - Why go from a compile time error to a runtime error? You aren't able to reason about the behavior of your program.


How does dependency injection change whether an error is compile time vs runtime errors in the slightest?

Why does it inhibit your ability to reason about your program? I would argue the opposite, that it clarifies in the intent of your program because each dependency is explicitly laid out at a single point in your class.

2) How many times have you really switched out an implementation of an object? I am being serious. How many times?


You don't need to switch the implementation of an object to realize the benefits of dependency injection. But you can.

We use it every day, because at the highest level, different build flavours use different implementations of the same classes. At a lower level, it allows us to switch between mock, staging and production endpoints at run-time.

3) It creates bad code - I want a dependency, let me see, someone created this object for me that will have a part of what I need. Let me just bring in their dependency and all their extra garbage with it. Remember, you are not going to be the person looking at this code in the future and modifying it, so any methods and objects are fair game to be misused.


This is an empty statement. Your code can always be misused. In fact, it's the other way around. Injecting allows you to establish an explicit contract that this feature will depend on this other feature. If you want to scope down a dependency, expose it as a separate interface, which can also be injected.

4) Object construction is actually necessary to write elegant code. Just because you can make something into an object doesn't mean it should be an object.


These two sentences contradict each other? I'm not sure what is the point being made.

There is absolutely object construction when using DI. Not sure where you get the idea that you shouldn't make objects when you have a DI framework.

5) Dependency Injection Magic - Significant amount of the times, people spend time figuring out the nuances of the DI framework instead of their actual code.


In the opposite manner, people spend too much time thinking about their code and not about how it lives in the framework of the application they are writing. Once the framework is set up, DI is invisible. Annotate and put in the constructor and be done for the majority of cases, really until you want to swap implementations, which is a feature of DI, not the core.

If DI doesn't work, it's almost always that it was written with another intent in mind. Or maybe it's just wrong. Scoped DI allows you to clarify the intent of where the object lives.




I don't disagree that DI is complicated. It is ridiculous hyperbole to suggest DI is "just a bad idea for a cluster fuck" though.
There is no one like you in the universe.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2017-12-07 09:27:48
December 07 2017 08:20 GMT
#18517
On December 06 2017 13:38 WarSame wrote:
Dagger 2 and GUICE were the main recommendations I read elsewhere, so thank you for giving more strength to those recommendations.

I'm finding it very hard to understand Patterns and concepts like DI. I understand that they make your code more flexible and maintainable. I've worked maintenance at a bank for the last 1.5 years so I understand why that's important. I find it hard to relate what these cerebral concepts are supposed to accomplish to concrete improvements in my code. Is it something you need to be on the maintaining end of to understand fully?


Sorry I didn't respond quickly, busy with work. DI is just one solution for some problems with its own set of inherent advantages (and disadvantages) that might not fit with how you envision software development, and might cause more pain because the frameworks are not perfect (though one could say that about almost anything in Android...). Keeping these objects in the Application, in the Activity, and managing that complexity yourself is perfectly valid. It's easy to think about planning ahead, but you aren't going to need it (YAGNI). That being said, DI is a big thing in Android and used by many companies.

Want to differentiate between DI and DI framework, I'll be talking more of DI as a framework, as DI by itself is just as though you had a smarter Factory.



Just to run through DI, ignore words like flexible and maintainable, those terms are too abstract IMO. Same thing with stuff like decoupling.

IMO the most important advantage of IOC and DI, is that it allows you to reason about your classes in a clearer way.

Day-to-day, your classes exist in a sea of other classes. Your classes consume the behaviors of other classes that live upstream, and provide your own behaviors downstream.

With DI, your object's constructor explicitly states all the other classes and behaviors your class consumes. This allows you to easily say that your class depends on the functionality of all these other classes. You don't really care about what these classes are or where they came from, but you care that these classes implicitly provide a "contract" about their functionality, in their public methods.

If your code is very mindful of this "contract" of public methods, then when you write a class, you can rely on any of these upstream dependencies, and simply use them. And then downstream, you can compose multiple classes in such a way, without caring about why the class exists and in what space, only that they provide the functionality that you expect. And DI lets you enforce this non-caring aspect, no need to deal with creating and managing your upstream and downstream dependencies, just inject them.



There are other benefits to scoping with DI, like being able to enforce and make assumptions about the persistence of a class.

Testing classes with this form of IOC looks similar to this idea of contracts. All I'm really testing for with mocks is that classes enforce the contract I'm expecting. i.e. the send() function actually makes a (mock) network call, that these functions actually modify the state in a way I expect, without caring where the function call is coming from.

Note that you can use DI with concrete classes, not just interfaces.
There is no one like you in the universe.
Acrofales
Profile Joined August 2010
Spain18102 Posts
Last Edited: 2017-12-07 10:33:32
December 07 2017 10:33 GMT
#18518
On December 07 2017 17:20 Blisse wrote:
Show nested quote +
On December 06 2017 13:38 WarSame wrote:
Dagger 2 and GUICE were the main recommendations I read elsewhere, so thank you for giving more strength to those recommendations.

I'm finding it very hard to understand Patterns and concepts like DI. I understand that they make your code more flexible and maintainable. I've worked maintenance at a bank for the last 1.5 years so I understand why that's important. I find it hard to relate what these cerebral concepts are supposed to accomplish to concrete improvements in my code. Is it something you need to be on the maintaining end of to understand fully?


Sorry I didn't respond quickly, busy with work. DI is just one solution for some problems with its own set of inherent advantages (and disadvantages) that might not fit with how you envision software development, and might cause more pain because the frameworks are not perfect (though one could say that about almost anything in Android...). Keeping these objects in the Application, in the Activity, and managing that complexity yourself is perfectly valid. It's easy to think about planning ahead, but you aren't going to need it (YAGNI). That being said, DI is a big thing in Android and used by many companies.

Want to differentiate between DI and DI framework, I'll be talking more of DI as a framework, as DI by itself is just as though you had a smarter Factory.



Just to run through DI, ignore words like flexible and maintainable, those terms are too abstract IMO. Same thing with stuff like decoupling.

IMO the most important advantage of IOC and DI, is that it allows you to reason about your classes in a clearer way.

Day-to-day, your classes exist in a sea of other classes. Your classes consume the behaviors of other classes that live upstream, and provide your own behaviors downstream.

With DI, your object's constructor explicitly states all the other classes and behaviors your class consumes. This allows you to easily say that your class depends on the functionality of all these other classes. You don't really care about what these classes are or where they came from, but you care that these classes implicitly provide a "contract" about their functionality, in their public methods.

If your code is very mindful of this "contract" of public methods, then when you write a class, you can rely on any of these upstream dependencies, and simply use them. And then downstream, you can compose multiple classes in such a way, without caring about why the class exists and in what space, only that they provide the functionality that you expect. And DI lets you enforce this non-caring aspect, no need to deal with creating and managing your upstream and downstream dependencies, just inject them.



There are other benefits to scoping with DI, like being able to enforce and make assumptions about the persistence of a class.

Testing classes with this form of IOC looks similar to this idea of contracts. All I'm really testing for with mocks is that classes enforce the contract I'm expecting. i.e. the send() function actually makes a (mock) network call, that these functions actually modify the state in a way I expect, without caring where the function call is coming from.

Note that you can use DI with concrete classes, not just interfaces.

Nowhere did I say DI is not a useful design pattern, but it is not a solution to the very specific problem warsame was having.

That said you seem to be attributing many advantages of interface based design (something that Java almost forces upon you, and Android definitely takes seriously) to dependency injection.

Unless I misunderstood what you're trying to say.

@warsame: if all you need is a single local account, accessible only to your app, then sharedpreferences is a perfectly good place to store that profile information and make it accessible throughout your app. If you have multiple local accounts, then there are better solutions.

phar
Profile Joined August 2011
United States1080 Posts
December 07 2017 16:53 GMT
#18519
On December 07 2017 04:56 Blisse wrote:
Show nested quote +
On December 07 2017 01:34 phar wrote:
On December 06 2017 04:18 Blisse wrote:

Just got this Google coding challenge terminal thing in the browser, it's weird.

If that's like while doing a Google search, it can result in a job.

Or at least a job interview.


I've already been flown out and interviewed and rejected by Google, twice :cries:

My excuse is, I didn't want to work there anyways!

Welp you can always try a third time. Lotta people don't make it initially.
Who after all is today speaking about the destruction of the Armenians?
sc-darkness
Profile Joined August 2017
856 Posts
Last Edited: 2017-12-07 17:44:50
December 07 2017 17:31 GMT
#18520
On December 07 2017 09:39 travis wrote:
What do you mean by "release"?

Also, what quicksort did you use? The most basic, or a variant?

I don't know what language that is, but some languages it's really really hard to beat the standard sort algorithm. It may be the case that your standard sort changes approach based on the circumstances.


Executables and library files could usually be output in two configurations - release (optimised) and debug (less optimised/unoptimised). For obvious reasons, you're meant to give release versions to customers because they run faster.

Back to your question about quicksort, this is the pseudo-code that I've followed. It's almost "as-is", I just had to make a few changes so it compiles. I believe it's basic quicksort. The language I use is C++.

+ Show Spoiler +


void quicksort(std::vector<int>& arr, size_t low, size_t high)
{
if (low < high)
{
size_t pivot_location = partition(arr, low, high);
quicksort(arr, low, pivot_location);
quicksort(arr, pivot_location + 1, high);
}
}

size_t partition(std::vector<int>& arr, size_t low, size_t high)
{
int pivot = arr[low];
size_t leftwall = low;

for (size_t i = low + 1; i < high; ++i)
{
if (arr[i] < pivot)
{
std::swap(arr[i], arr[leftwall]);
leftwall += 1;
}
}

std::swap(pivot, arr[leftwall]);

return leftwall;
}



If you have a std::vector<int>, then you sort it as follows:
quicksort(array, 0, array.size());


To others: I've not bothered to polish code too much, I'm sure it could be improved. I'm just interested in algorithm itself.
I also know about std::sort but this is just for educational purposes.

Edit: Wow, C++ gives you a lot of helper functions you need to implement algorithms on your own. Just to name a few:

std::swap
std::make_heap - max-heap data structure
std::shuffle
std::partition
std::merge
Prev 1 924 925 926 927 928 1032 Next
Please log in or register to reply.
Live Events Refresh
Replay Cast
23:00
Crank Gathers S2: Playoffs D2
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SortOf 119
Nina 70
StarCraft: Brood War
Hyuk 4148
Flash 2445
Sea 1773
Killer 1225
Bisu 418
Hyun 358
Larva 213
Stork 181
Shinee 53
EffOrt 43
[ Show more ]
ToSsGirL 37
yabsab 23
Sharp 12
Sacsri 9
Free 5
Dota 2
XaKoH 545
NeuroSwarm114
ODPixel58
League of Legends
JimRising 689
Super Smash Bros
Mew2King230
Other Games
summit1g14165
ceh9370
Organizations
Counter-Strike
PGL7201
Other Games
gamesdonequick666
StarCraft: Brood War
UltimateBattle 26
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• Berry_CruncH272
• LUISG 9
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• iopq 1
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Jankos2022
• Lourlo804
Upcoming Events
The PondCast
12m
OSC
3h 12m
Harstem vs SKillous
Gerald vs Spirit
Krystianer vs TriGGeR
Cham vs Ryung
CrankTV Team League
4h 12m
Team Liquid vs Team Falcon
Replay Cast
1d 1h
WardiTV Invitational
1d 3h
ByuN vs Spirit
herO vs Solar
MaNa vs Gerald
Rogue vs GuMiho
Epic.LAN
1d 3h
CrankTV Team League
1d 4h
BASILISK vs TBD
Replay Cast
2 days
Epic.LAN
2 days
BSL Team A[vengers]
2 days
Dewalt vs Shine
UltrA vs ZeLoT
[ Show More ]
BSL 21
2 days
Sparkling Tuna Cup
3 days
BSL Team A[vengers]
3 days
Cross vs Motive
Sziky vs HiyA
BSL 21
3 days
Wardi Open
4 days
Monday Night Weeklies
4 days
Liquipedia Results

Completed

CSL 2025 AUTUMN (S18)
WardiTV TLMC #15
Eternal Conflict S1

Ongoing

BSL 21 Points
BSL 21 Team A
C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
CranK Gathers Season 2: SC II Pro Teams
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025

Upcoming

SC4ALL: Brood War
YSL S2
BSL Season 21
SLON Tour Season 2
BSL 21 Non-Korean Championship
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
Stellar Fest
SC4ALL: StarCraft II
META Madness #9
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.