• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 02:53
CEST 08:53
KST 15:53
  • 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
RSL Season 1 - Final Week6[ASL19] Finals Recap: Standing Tall12HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0
Community News
Team TLMC #5 - Submission extension1Firefly given lifetime ban by ESIC following match-fixing investigation17$25,000 Streamerzone StarCraft Pro Series announced7Weekly Cups (June 30 - July 6): Classic Doubles7[BSL20] Non-Korean Championship 4x BSL + 4x China11
StarCraft 2
General
TL Team Map Contest #5: Presented by Monster Energy Team TLMC #5 - Submission extension RSL Revival patreon money discussion thread The GOAT ranking of GOAT rankings Weekly Cups (June 30 - July 6): Classic Doubles
Tourneys
$5,100+ SEL Season 2 Championship (SC: Evo) WardiTV Mondays RSL: Revival, a new crowdfunded tournament series Sparkling Tuna Cup - Weekly Open Tournament FEL Cracov 2025 (July 27) - $8000 live event
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
External Content
Mutation # 482 Wheel of Misfortune Mutation # 481 Fear and Lava Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome
Brood War
General
A cwal.gg Extension - Easily keep track of anyone Flash Announces Hiatus From ASL [Guide] MyStarcraft BW General Discussion [ASL19] Finals Recap: Standing Tall
Tourneys
[BSL20] Non-Korean Championship 4x BSL + 4x China [Megathread] Daily Proleagues 2025 ACS Season 2 Qualifier Small VOD Thread 2.0
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Path of Exile CCLP - Command & Conquer League Project The PlayStation 5
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread Summer Games Done Quick 2025! Things Aren’t Peaceful in Palestine The Accidental Video Game Porn Archive
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread [\m/] Heavy Metal Thread
Sports
2024 - 2025 Football Thread Formula 1 Discussion NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Men Take Risks, Women Win Ga…
TrAiDoS
momentary artworks from des…
tankgirl
from making sc maps to makin…
Husyelt
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 512 users

The Big Programming Thread - Page 926

Forum Index > General Forum
Post a Reply
Prev 1 924 925 926 927 928 1031 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
Spain17975 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
Norway8058 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
Spain17975 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 1031 Next
Please log in or register to reply.
Live Events Refresh
Next event in 4h 7m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Nina 270
StarCraft: Brood War
PianO 602
Free 593
Leta 176
Dewaltoss 76
Shine 28
Noble 19
Bale 8
Dota 2
monkeys_forever749
XcaliburYe28
League of Legends
JimRising 788
Counter-Strike
Stewie2K1080
Super Smash Bros
Mew2King269
Westballz31
Heroes of the Storm
Khaldor123
Other Games
summit1g12853
ViBE238
NeuroSwarm58
SortOf56
Organizations
Other Games
gamesdonequick5037
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• Berry_CruncH377
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• lizZardDota2115
League of Legends
• Rush2549
• HappyZerGling92
Upcoming Events
Wardi Open
4h 7m
Replay Cast
1d 3h
WardiTV European League
1d 9h
ShoWTimE vs sebesdes
Percival vs NightPhoenix
Shameless vs Nicoract
Krystianer vs Scarlett
ByuN vs uThermal
Harstem vs HeRoMaRinE
PiGosaur Monday
1d 17h
uThermal 2v2 Circuit
2 days
Replay Cast
2 days
The PondCast
3 days
Replay Cast
3 days
Epic.LAN
4 days
CranKy Ducklings
5 days
[ Show More ]
Epic.LAN
5 days
BSL20 Non-Korean Champi…
5 days
Bonyth vs Sziky
Dewalt vs Hawk
Hawk vs QiaoGege
Sziky vs Dewalt
Mihu vs Bonyth
Zhanhun vs QiaoGege
QiaoGege vs Fengzi
Sparkling Tuna Cup
6 days
Online Event
6 days
BSL20 Non-Korean Champi…
6 days
Bonyth vs Zhanhun
Dewalt vs Mihu
Hawk vs Sziky
Sziky vs QiaoGege
Mihu vs Hawk
Zhanhun vs Dewalt
Fengzi vs Bonyth
Liquipedia Results

Completed

2025 ACS Season 2: Qualifier
RSL Revival: Season 1
Murky Cup #2

Ongoing

JPL Season 2
BSL 2v2 Season 3
Copa Latinoamericana 4
Jiahua Invitational
BSL20 Non-Korean Championship
Championship of Russia 2025
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters

Upcoming

CSL Xiamen Invitational
CSL Xiamen Invitational: ShowMatche
2025 ACS Season 2
CSLPRO Last Chance 2025
CSLPRO Chat StarLAN 3
BSL Season 21
K-Championship
RSL Revival: Season 2
SEL Season 2 Championship
uThermal 2v2 Main Event
FEL Cracov 2025
Esports World Cup 2025
Underdog Cup #2
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
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.