• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 01:35
CET 06:35
KST 14:35
  • 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
[ASL21] Ro24 Preview Pt1: New Chaos0Team Liquid Map Contest #22 - Presented by Monster Energy7ByuL: The Forgotten Master of ZvT30Behind the Blue - Team Liquid History Book20Clem wins HomeStory Cup 289
Community News
Weekly Cups (March 16-22): herO doubles, Cure surprises3Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool48Weekly Cups (March 9-15): herO, Clem, ByuN win42026 KungFu Cup Announcement6BGE Stara Zagora 2026 cancelled12
StarCraft 2
General
What mix of new & old maps do you want in the next ladder pool? (SC2) Potential Updates Coming to the SC2 CN Server Behind the Blue - Team Liquid History Book herO wins SC2 All-Star Invitational Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool
Tourneys
StarCraft Evolution League (SC Evo Biweekly) WardiTV Mondays Sparkling Tuna Cup - Weekly Open Tournament World University TeamLeague (500$+) | Signups Open RSL Season 4 announced for March-April
Strategy
Custom Maps
[M] (2) Frigid Storage Publishing has been re-enabled! [Feb 24th 2026]
External Content
The PondCast: SC2 News & Results Mutation # 518 Radiation Zone Mutation # 517 Distant Threat Mutation # 516 Specter of Death
Brood War
General
Recent recommended BW games ASL21 General Discussion Gypsy to Korea RepMastered™: replay sharing and analyzer site KK Platform will provide 1 million CNY
Tourneys
[Megathread] Daily Proleagues 2026 Changsha Offline Cup [ASL21] Ro24 Group B [ASL21] Ro24 Group A
Strategy
What's the deal with APM & what's its true value Fighting Spirit mining rates Simple Questions, Simple Answers Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Darkest Dungeon General RTS Discussion Thread Path of Exile
Dota 2
The Story of Wings Gaming Official 'what is Dota anymore' discussion
League of Legends
G2 just beat GenG in First stand
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 Five o'clock TL Mafia Mafia Game Mode Feedback/Ideas Vanilla Mini Mafia
Community
General
US Politics Mega-thread The Games Industry And ATVI European Politico-economics QA Mega-thread Canadian Politics Mega-thread Russo-Ukrainian War Thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
[Manga] One Piece [Req][Books] Good Fantasy/SciFi books Movie Discussion!
Sports
2024 - 2026 Football Thread Cricket [SPORT] Formula 1 Discussion Tokyo Olympics 2021 Thread General nutrition recommendations
World Cup 2022
Tech Support
[G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
Funny Nicknames
LUCKY_NOOB
Money Laundering In Video Ga…
TrAiDoS
Iranian anarchists: organize…
XenOsky
FS++
Kraekkling
Shocked by a laser…
Spydermine0240
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 9001 users

The Big Programming Thread - Page 957

Forum Index > General Forum
Post a Reply
Prev 1 955 956 957 958 959 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.
Uldridge
Profile Blog Joined January 2011
Belgium5070 Posts
Last Edited: 2018-05-01 01:47:18
May 01 2018 01:05 GMT
#19121
A small question from a quite inorant point of view to the general computer scientist/programmer/engineer so excuse me if it sounds ridiculous to you.

How much control do you exert on your operating system? Do you use it like an average window user and just boot all your programs to use, or do you fiddle under the hood a little bit, have scripts running, monitoring all sorts of stuff like network/performance/hardware usage/resource allocation/... or even go so far as to customize/personally upgrade your OS to the point it vastly outperforms the standard package?
Taxes are for Terrans
ShoCkeyy
Profile Blog Joined July 2008
7815 Posts
May 01 2018 01:26 GMT
#19122
I currently have a hackintosh, so I definitely have full control of the hardware, as for the scripts, I have a few that run on startup to get my day going faster, but I mostly moniter my machine with what already came with it, like Task manager or Activity monitor. As far as customizing how my OS looks, yea definitely a lot of tweaking to have it look different
Life?
Lmui
Profile Joined November 2010
Canada6223 Posts
May 01 2018 01:39 GMT
#19123
I change the wallpaper, icon/text size and that's about it.

Tweaks:
Ultimate windows tweaker and removed the arrow from shortcuts.

I'm very much a casual operating system user, regardless of how much of a power user I am at anything else.

Mobile:
I have Nova launcher and I changed a few things but largely stock. Not much reason to go full cyanogen with anything any more.
berated-
Profile Blog Joined February 2007
United States1134 Posts
Last Edited: 2018-05-01 04:46:29
May 01 2018 04:44 GMT
#19124
On April 30 2018 12:39 WarSame wrote:
I need a lot of help understanding Dagger 2. I've read a lot of guides and I don't understand DI in general.

You have an object you want to inject. You Provide it with @Provides inside of an @Module. You then use it somewhere else with @Inject. Is this correct so far?

If it is I'm failing to apply it to my cause and getting errors that aren't google-able.

In my case I am trying to inject an instance of a javax.crypto.KeyGenerator. I created a Module AppComponent with an @Provides KeyGenerator provideKeyGenerator(String walletName). I then want to @Inject this into another Class with certain parameters but I can't get that to work. I've tried a number of things, but keep running into problems injecting it, because it runs into problems injecting into a static field.

Does anyone have a good, basic guide for doing something like this? I feel like I'm running into a wall with this. I'll try to post some sample code tomorrow night to give this post an actual purpose.


I haven't played around with dagger a whole lot, but, I'm a pretty big spring fan boy, so maybe that makes me qualified to help?

Dependency injection is most often used to help implement the Inversion of Control pattern. The entire point is that one does not know where or how their dependencies are constructed, just that they need the service. The base example I always go back to is a print service in java. I don't care how the printer implementation is done, I just know that I need someone that can print, so I'm going to request such a service with my @Inject.

The reason I point this out, is when you say you just need a key generator with certain parameters, it feels like it doesn't line up with IoC in the way previously mentioned. IoC would work best if you just said, hey,I need a key generator, not with certain parameters. That's where in the Java world where we love our patterns, the factory pattern comes in. In your case you don't just need a keygenerator, you need one who knows how to make key generators. You could inject that in, and then use that method.

All of this is kind of eclipsed by the fact that you then mention statics. This isnt' to say that statics are bad, it's just that, they aren't often used with DI. One of the reasons that DI is so popular is that when you aren't specifying your implementation, but yet the interface that you need -- one can provide a completely different implementation under test that can skip hard integration and allow for easier unit testing with mocks or test doubles. Specifying a concrete implementation into a static field doesn't help that much for test-ability in most cases.

If you would like to get into more specifics I would be glad to ramble more.

spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
May 01 2018 07:31 GMT
#19125
I use windows mostly like a regular user. I'll only look at resource usage etc. if something seems off. I guess the biggest change I made is relocating my user folder to the D: drive. Other than that just some basic settings like showing file extensions and hidden folders, turning off mouse acceleration, multiple input schemes... but all of that is easily available to the average user.
If you have a good reason to disagree with the above, please tell me. Thank you.
bo1b
Profile Blog Joined August 2012
Australia12814 Posts
May 01 2018 07:57 GMT
#19126
I use arch linux with xmonad (just to really get a better feel for haskell), Depending on what I need to do I have a dual boot windows on hand. I used to use pci pass through but I pretty much have stopped playing games for the most part, and use windows so rarely currently that I just don't care to stuff around with that much of a hassle. I have spent almost no time customizing my background as I simply don't give a shit, though I've spent a lot of time setting up spacemacs to do what I want to do. If for whatever reason I need to do some web editing, I have intellij ready to go at a moments notice, though again, I have an emacs set up that's significantly better in some regards.
Manit0u
Profile Blog Joined August 2004
Poland17706 Posts
May 01 2018 08:03 GMT
#19127
On May 01 2018 13:44 berated- wrote:
Show nested quote +
On April 30 2018 12:39 WarSame wrote:
I need a lot of help understanding Dagger 2. I've read a lot of guides and I don't understand DI in general.

You have an object you want to inject. You Provide it with @Provides inside of an @Module. You then use it somewhere else with @Inject. Is this correct so far?

If it is I'm failing to apply it to my cause and getting errors that aren't google-able.

In my case I am trying to inject an instance of a javax.crypto.KeyGenerator. I created a Module AppComponent with an @Provides KeyGenerator provideKeyGenerator(String walletName). I then want to @Inject this into another Class with certain parameters but I can't get that to work. I've tried a number of things, but keep running into problems injecting it, because it runs into problems injecting into a static field.

Does anyone have a good, basic guide for doing something like this? I feel like I'm running into a wall with this. I'll try to post some sample code tomorrow night to give this post an actual purpose.


I haven't played around with dagger a whole lot, but, I'm a pretty big spring fan boy, so maybe that makes me qualified to help?

Dependency injection is most often used to help implement the Inversion of Control pattern. The entire point is that one does not know where or how their dependencies are constructed, just that they need the service. The base example I always go back to is a print service in java. I don't care how the printer implementation is done, I just know that I need someone that can print, so I'm going to request such a service with my @Inject.

The reason I point this out, is when you say you just need a key generator with certain parameters, it feels like it doesn't line up with IoC in the way previously mentioned. IoC would work best if you just said, hey,I need a key generator, not with certain parameters. That's where in the Java world where we love our patterns, the factory pattern comes in. In your case you don't just need a keygenerator, you need one who knows how to make key generators. You could inject that in, and then use that method.

All of this is kind of eclipsed by the fact that you then mention statics. This isnt' to say that statics are bad, it's just that, they aren't often used with DI. One of the reasons that DI is so popular is that when you aren't specifying your implementation, but yet the interface that you need -- one can provide a completely different implementation under test that can skip hard integration and allow for easier unit testing with mocks or test doubles. Specifying a concrete implementation into a static field doesn't help that much for test-ability in most cases.

If you would like to get into more specifics I would be glad to ramble more.



The word "static" shouldn't really be used in OOP (speaking from pure OOP perspective). Although I like it on some abstract or final classes to get some "hard-coded" properties going.
Time is precious. Waste it wisely.
Acrofales
Profile Joined August 2010
Spain18246 Posts
May 01 2018 09:10 GMT
#19128
On May 01 2018 16:31 spinesheath wrote:
I use windows mostly like a regular user. I'll only look at resource usage etc. if something seems off. I guess the biggest change I made is relocating my user folder to the D: drive. Other than that just some basic settings like showing file extensions and hidden folders, turning off mouse acceleration, multiple input schemes... but all of that is easily available to the average user.

Pretty much this. And the same for my ubuntu. I installed a dual boot because I mostly prefer working in Linux for development, but need Windows for the odd thing. Both have some minor tweaks but nothing beyond some UI tweaks to make it a bit more comfortable for me. I'll only really worry about monitoring resources when things get awfully slow for no reason I can really think of.
nunez
Profile Blog Joined February 2011
Norway4003 Posts
May 01 2018 16:21 GMT
#19129
On May 01 2018 17:03 Manit0u wrote:
Show nested quote +
On May 01 2018 13:44 berated- wrote:
On April 30 2018 12:39 WarSame wrote:
I need a lot of help understanding Dagger 2. I've read a lot of guides and I don't understand DI in general.

You have an object you want to inject. You Provide it with @Provides inside of an @Module. You then use it somewhere else with @Inject. Is this correct so far?

If it is I'm failing to apply it to my cause and getting errors that aren't google-able.

In my case I am trying to inject an instance of a javax.crypto.KeyGenerator. I created a Module AppComponent with an @Provides KeyGenerator provideKeyGenerator(String walletName). I then want to @Inject this into another Class with certain parameters but I can't get that to work. I've tried a number of things, but keep running into problems injecting it, because it runs into problems injecting into a static field.

Does anyone have a good, basic guide for doing something like this? I feel like I'm running into a wall with this. I'll try to post some sample code tomorrow night to give this post an actual purpose.


I haven't played around with dagger a whole lot, but, I'm a pretty big spring fan boy, so maybe that makes me qualified to help?

Dependency injection is most often used to help implement the Inversion of Control pattern. The entire point is that one does not know where or how their dependencies are constructed, just that they need the service. The base example I always go back to is a print service in java. I don't care how the printer implementation is done, I just know that I need someone that can print, so I'm going to request such a service with my @Inject.

The reason I point this out, is when you say you just need a key generator with certain parameters, it feels like it doesn't line up with IoC in the way previously mentioned. IoC would work best if you just said, hey,I need a key generator, not with certain parameters. That's where in the Java world where we love our patterns, the factory pattern comes in. In your case you don't just need a keygenerator, you need one who knows how to make key generators. You could inject that in, and then use that method.

All of this is kind of eclipsed by the fact that you then mention statics. This isnt' to say that statics are bad, it's just that, they aren't often used with DI. One of the reasons that DI is so popular is that when you aren't specifying your implementation, but yet the interface that you need -- one can provide a completely different implementation under test that can skip hard integration and allow for easier unit testing with mocks or test doubles. Specifying a concrete implementation into a static field doesn't help that much for test-ability in most cases.

If you would like to get into more specifics I would be glad to ramble more.



The word "static" shouldn't really be used in OOP (speaking from pure OOP perspective). Although I like it on some abstract or final classes to get some "hard-coded" properties going.

the semantics of static is tied to a particular language and context. can you go into a bit more detail about the alleged contradiction between static and OOP for C++?
conspired against by a confederacy of dunces.
nunez
Profile Blog Joined February 2011
Norway4003 Posts
Last Edited: 2018-05-01 17:06:53
May 01 2018 16:33 GMT
#19130
On May 01 2018 16:57 bo1b wrote:
I use arch linux with xmonad (just to really get a better feel for haskell), Depending on what I need to do I have a dual boot windows on hand. I used to use pci pass through but I pretty much have stopped playing games for the most part, and use windows so rarely currently that I just don't care to stuff around with that much of a hassle. I have spent almost no time customizing my background as I simply don't give a shit, though I've spent a lot of time setting up spacemacs to do what I want to do. If for whatever reason I need to do some web editing, I have intellij ready to go at a moments notice, though again, I have an emacs set up that's significantly better in some regards.


this is me almost. except i use i3 instead of xmonad, and emacs instead of spacemacs. i switched from vim recently, very fun and painful. the way i use emacs tends to make me rely a bit less on the windows manager and the shell, which maybe is a bit worriesome, and un-unix like. maybe if used emacs server / client instead this would not be an issue. however i chose the easier path.

i try to homogenize hotkeys (f.ex. navigation) and theme across the programs i use in a programming context (windows-manager, text-editor, shell), but i don't bother customizing other software. i have a nice background photo that reminds me of relaxing in nature, the opposite of working with programming, but my tiling window manager makes sure i never get to see it.

i am planning to transition to guixsd from arch linux. but i did not find the time yet. i really do like arch, but i want to try something new. hopefully it will not be as short-lived as my excursion into gentoo.
conspired against by a confederacy of dunces.
nunez
Profile Blog Joined February 2011
Norway4003 Posts
May 01 2018 17:15 GMT
#19131
the gcc and gdb integration on emacs was such a nice experience.

except i had to swap some of the regexi the gdb-integration uses that was causing stack-overflow due to the symbol-names of my binaries being huge because of meta-programming. nothing somebody haven't already worked around and shared though.

the gcc integration seems to be a bit slow dealing with your typical gcc-template spew. i'm sure i can fix this as well, but as of now it is working alright.
conspired against by a confederacy of dunces.
Silvanel
Profile Blog Joined March 2003
Poland4744 Posts
May 01 2018 18:46 GMT
#19132
On May 02 2018 01:21 nunez wrote:
Show nested quote +
On May 01 2018 17:03 Manit0u wrote:
On May 01 2018 13:44 berated- wrote:
On April 30 2018 12:39 WarSame wrote:
I need a lot of help understanding Dagger 2. I've read a lot of guides and I don't understand DI in general.

You have an object you want to inject. You Provide it with @Provides inside of an @Module. You then use it somewhere else with @Inject. Is this correct so far?

If it is I'm failing to apply it to my cause and getting errors that aren't google-able.

In my case I am trying to inject an instance of a javax.crypto.KeyGenerator. I created a Module AppComponent with an @Provides KeyGenerator provideKeyGenerator(String walletName). I then want to @Inject this into another Class with certain parameters but I can't get that to work. I've tried a number of things, but keep running into problems injecting it, because it runs into problems injecting into a static field.

Does anyone have a good, basic guide for doing something like this? I feel like I'm running into a wall with this. I'll try to post some sample code tomorrow night to give this post an actual purpose.


I haven't played around with dagger a whole lot, but, I'm a pretty big spring fan boy, so maybe that makes me qualified to help?

Dependency injection is most often used to help implement the Inversion of Control pattern. The entire point is that one does not know where or how their dependencies are constructed, just that they need the service. The base example I always go back to is a print service in java. I don't care how the printer implementation is done, I just know that I need someone that can print, so I'm going to request such a service with my @Inject.

The reason I point this out, is when you say you just need a key generator with certain parameters, it feels like it doesn't line up with IoC in the way previously mentioned. IoC would work best if you just said, hey,I need a key generator, not with certain parameters. That's where in the Java world where we love our patterns, the factory pattern comes in. In your case you don't just need a keygenerator, you need one who knows how to make key generators. You could inject that in, and then use that method.

All of this is kind of eclipsed by the fact that you then mention statics. This isnt' to say that statics are bad, it's just that, they aren't often used with DI. One of the reasons that DI is so popular is that when you aren't specifying your implementation, but yet the interface that you need -- one can provide a completely different implementation under test that can skip hard integration and allow for easier unit testing with mocks or test doubles. Specifying a concrete implementation into a static field doesn't help that much for test-ability in most cases.

If you would like to get into more specifics I would be glad to ramble more.



The word "static" shouldn't really be used in OOP (speaking from pure OOP perspective). Although I like it on some abstract or final classes to get some "hard-coded" properties going.

the semantics of static is tied to a particular language and context. can you go into a bit more detail about the alleged contradiction between static and OOP for C++?


Deosnt Java, C, C# , Rust (and probably more) also use static?? I mean this indeed feels like huge generalization.
Pathetic Greta hater.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
May 01 2018 20:24 GMT
#19133
On April 30 2018 12:39 WarSame wrote:
I need a lot of help understanding Dagger 2. I've read a lot of guides and I don't understand DI in general.

You have an object you want to inject. You Provide it with @Provides inside of an @Module. You then use it somewhere else with @Inject. Is this correct so far?

If it is I'm failing to apply it to my cause and getting errors that aren't google-able.

In my case I am trying to inject an instance of a javax.crypto.KeyGenerator. I created a Module AppComponent with an @Provides KeyGenerator provideKeyGenerator(String walletName). I then want to @Inject this into another Class with certain parameters but I can't get that to work. I've tried a number of things, but keep running into problems injecting it, because it runs into problems injecting into a static field.

Does anyone have a good, basic guide for doing something like this? I feel like I'm running into a wall with this. I'll try to post some sample code tomorrow night to give this post an actual purpose.


For your case, your Application needs to store an instance of the AppComponent object, and you'll do something like `Application.getInstance.inject(this)`.

I've never tried injecting into static fields, but I wouldn't be surprised if that doesn't work. You're basically subverting the whole point of using a dependency injection framework.

IMO this (https://www.techyourchance.com/dagger-tutorial/) is a simple Dagger tutorial that should get you running. Vasiliy has good ideas about Dagger. I would also check r/androiddev if you have any Android specific questions, more actives there.
There is no one like you in the universe.
nunez
Profile Blog Joined February 2011
Norway4003 Posts
Last Edited: 2018-05-01 20:51:30
May 01 2018 20:50 GMT
#19134
On May 02 2018 03:46 Silvanel wrote:
Show nested quote +
On May 02 2018 01:21 nunez wrote:
On May 01 2018 17:03 Manit0u wrote:
On May 01 2018 13:44 berated- wrote:
On April 30 2018 12:39 WarSame wrote:
I need a lot of help understanding Dagger 2. I've read a lot of guides and I don't understand DI in general.

You have an object you want to inject. You Provide it with @Provides inside of an @Module. You then use it somewhere else with @Inject. Is this correct so far?

If it is I'm failing to apply it to my cause and getting errors that aren't google-able.

In my case I am trying to inject an instance of a javax.crypto.KeyGenerator. I created a Module AppComponent with an @Provides KeyGenerator provideKeyGenerator(String walletName). I then want to @Inject this into another Class with certain parameters but I can't get that to work. I've tried a number of things, but keep running into problems injecting it, because it runs into problems injecting into a static field.

Does anyone have a good, basic guide for doing something like this? I feel like I'm running into a wall with this. I'll try to post some sample code tomorrow night to give this post an actual purpose.


I haven't played around with dagger a whole lot, but, I'm a pretty big spring fan boy, so maybe that makes me qualified to help?

Dependency injection is most often used to help implement the Inversion of Control pattern. The entire point is that one does not know where or how their dependencies are constructed, just that they need the service. The base example I always go back to is a print service in java. I don't care how the printer implementation is done, I just know that I need someone that can print, so I'm going to request such a service with my @Inject.

The reason I point this out, is when you say you just need a key generator with certain parameters, it feels like it doesn't line up with IoC in the way previously mentioned. IoC would work best if you just said, hey,I need a key generator, not with certain parameters. That's where in the Java world where we love our patterns, the factory pattern comes in. In your case you don't just need a keygenerator, you need one who knows how to make key generators. You could inject that in, and then use that method.

All of this is kind of eclipsed by the fact that you then mention statics. This isnt' to say that statics are bad, it's just that, they aren't often used with DI. One of the reasons that DI is so popular is that when you aren't specifying your implementation, but yet the interface that you need -- one can provide a completely different implementation under test that can skip hard integration and allow for easier unit testing with mocks or test doubles. Specifying a concrete implementation into a static field doesn't help that much for test-ability in most cases.

If you would like to get into more specifics I would be glad to ramble more.



The word "static" shouldn't really be used in OOP (speaking from pure OOP perspective). Although I like it on some abstract or final classes to get some "hard-coded" properties going.

the semantics of static is tied to a particular language and context. can you go into a bit more detail about the alleged contradiction between static and OOP for C++?


Deosnt Java, C, C# , Rust (and probably more) also use static?? I mean this indeed feels like huge generalization.


yes, exactly. i am only familiar with its semantics in C and C++, and it is not immediately obvious to me how OOP and static are contradictory here. it would be an interesting read.
conspired against by a confederacy of dunces.
Manit0u
Profile Blog Joined August 2004
Poland17706 Posts
Last Edited: 2018-05-01 22:17:48
May 01 2018 22:14 GMT
#19135
It depends on how you use them, but most of the time static properties (methods, variables, attributes, you name it) break encapsulation and introduce global state, which you usually want to avoid. Do you really, really need a method to be globally accessible?

Every time you want to use the static keyword in an OOP language you should ask yourself some questions first:
1. Do you really need a method that can be called without instantiating an object?
2. If your answer to #1 was "yes" then you must ask yourself if this breaks the single responsibility principle?
3. In any case, maybe this code could be moved to a different class altogether and not make it static?

The only reasons I've found to use static props was for some helper classes, preferably making them abstract so that they're never instantiated (man, sometimes I really wish you could use both final and abstract at the same time). Usually they're used for storing some kind of system setting stuff that has to be hardcoded.

Perhaps I'm dead wrong, but that's my take on it
Time is precious. Waste it wisely.
IyMoon
Profile Joined April 2016
United States1249 Posts
May 01 2018 22:49 GMT
#19136
I have a really random question.

I have a script that takes an int parameter and also queries a SQL table to get its row counts, and stores the row counts as an array. Then I need to check if the number provided in the parameter is inside this array.

Is it every faster to convert the array into a hash then do a hash look up vs just iterating through the array and checking if each number in the array is == to the parameter?

I know its a dumb question but I am curious


Something witty
Acrofales
Profile Joined August 2010
Spain18246 Posts
May 01 2018 23:19 GMT
#19137
On May 02 2018 07:49 IyMoon wrote:
I have a really random question.

I have a script that takes an int parameter and also queries a SQL table to get its row counts, and stores the row counts as an array. Then I need to check if the number provided in the parameter is inside this array.

Is it every faster to convert the array into a hash then do a hash look up vs just iterating through the array and checking if each number in the array is == to the parameter?

I know its a dumb question but I am curious



Building the hash is O(n log n). Lookup is then O(1). Alternatively, iterating through an array is O(n). So it depends on how many times you have to look something up.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2018-05-02 01:51:04
May 02 2018 01:46 GMT
#19138
the array should be faster unless, like acrofales is saying, you don't know where the value is so you have to iterate through the array

but if that's the case then there is probably a better design you could use, where you avoid that problem
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
May 02 2018 17:01 GMT
#19139
Static only really becomes bad if you combine it with mutability. And I make a special exception for caches, as long as the static part is private and you never remove elements from the cache/modify elements in the cache.
If you have a good reason to disagree with the above, please tell me. Thank you.
Manit0u
Profile Blog Joined August 2004
Poland17706 Posts
Last Edited: 2018-05-02 18:16:05
May 02 2018 18:00 GMT
#19140
On May 03 2018 02:01 spinesheath wrote:
Static only really becomes bad if you combine it with mutability. And I make a special exception for caches, as long as the static part is private and you never remove elements from the cache/modify elements in the cache.


Private static is fine for the most part. Public static is where things get hectic.

Here's a nice and brief explanation:
https://dzone.com/articles/why-static-bad-and-how-avoid

Edit:

Also, speaking of DI and encapsulation I think that Symfony project in PHP world is doing a great thing. They're basically forcing you to do nice and clean DI as they won't allow typehinting arguments to constructors with concrete classes, you can only specify interfaces and then inject whatever you want that implements this interface. Very neat.
Time is precious. Waste it wisely.
Prev 1 955 956 957 958 959 1032 Next
Please log in or register to reply.
Live Events Refresh
The PiG Daily
22:00
Best Games of SC
Maru vs Solar
Rogue vs MaxPax
herO vs Clem
SHIN vs ByuN
herO vs SHIN
TBD vs ByuN
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
-ZergGirl 205
ProTech33
StarCraft: Brood War
Shuttle 361
Tasteless 106
Dewaltoss 80
sSak 39
Noble 33
scan(afreeca) 14
Dota 2
febbydoto20
LuMiX1
League of Legends
JimRising 627
Counter-Strike
m0e_tv616
Other Games
summit1g8869
WinterStarcraft443
C9.Mang0432
crisheroes278
Nina108
Organizations
Other Games
BasetradeTV103
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• Berry_CruncH255
• Sammyuel 17
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• RayReign 28
• Azhi_Dahaki24
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Upcoming Events
RSL Revival
4h 26m
Cure vs Zoun
herO vs Rogue
Platinum Heroes Events
9h 26m
BSL
14h 26m
RSL Revival
1d 4h
ByuN vs Maru
MaxPax vs TriGGeR
WardiTV Team League
1d 6h
BSL
1d 13h
Replay Cast
1d 18h
Replay Cast
2 days
Afreeca Starleague
2 days
Light vs Calm
Royal vs Mind
Wardi Open
2 days
[ Show More ]
Monday Night Weeklies
2 days
OSC
2 days
Sparkling Tuna Cup
3 days
Afreeca Starleague
3 days
Rush vs PianO
Flash vs Speed
Replay Cast
4 days
Afreeca Starleague
4 days
BeSt vs Leta
Queen vs Jaedong
Replay Cast
4 days
The PondCast
5 days
Replay Cast
5 days
RSL Revival
6 days
Replay Cast
6 days
Liquipedia Results

Completed

KCM Race Survival 2026 Season 1
WardiTV Winter 2026
Underdog Cup #3

Ongoing

BSL Season 22
CSL Elite League 2026
CSL Season 20: Qualifier 1
ASL Season 21
Acropolis #4 - TS6
2026 Changsha Offline CUP
RSL Revival: Season 4
Nations Cup 2026
NationLESS Cup
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual

Upcoming

CSL Season 20: Qualifier 2
CSL 2026 SPRING (S20)
Acropolis #4
IPSL Spring 2026
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 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 © 2026 TLnet. All Rights Reserved.