• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 12:30
CEST 18:30
KST 01:30
  • 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
[ASL19] Finals Recap: Standing Tall9HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy6
Community News
Weekly Cups (June 30 - July 6): Classic Doubles2[BSL20] Non-Korean Championship 4x BSL + 4x China8Flash Announces Hiatus From ASL66Weekly Cups (June 23-29): Reynor in world title form?14FEL Cracov 2025 (July 27) - $8000 live event22
StarCraft 2
General
The SCII GOAT: A statistical Evaluation The GOAT ranking of GOAT rankings Weekly Cups (June 23-29): Reynor in world title form? Weekly Cups (June 30 - July 6): Classic Doubles Program: SC2 / XSplit / OBS Scene Switcher
Tourneys
RSL: Revival, a new crowdfunded tournament series FEL Cracov 2025 (July 27) - $8000 live event Sparkling Tuna Cup - Weekly Open Tournament WardiTV Mondays Korean Starcraft League Week 77
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 481 Fear and Lava Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma
Brood War
General
Flash Announces Hiatus From ASL SC uni coach streams logging into betting site BW General Discussion BGH Auto Balance -> http://bghmmr.eu/ ASL20 Preliminary Maps
Tourneys
[BSL20] Grand Finals - Sunday 20:00 CET CSL Xiamen International Invitational [BSL20] Non-Korean Championship 4x BSL + 4x China The Casual Games of the Week Thread
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 What do you want from future RTS games? Beyond All Reason
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
US Politics Mega-thread Russo-Ukrainian War Thread Stop Killing Games - European Citizens Initiative Summer Games Done Quick 2024! Summer Games Done Quick 2025!
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread
Sports
Formula 1 Discussion 2024 - 2025 Football Thread 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
Culture Clash in Video Games…
TrAiDoS
from making sc maps to makin…
Husyelt
Blog #2
tankgirl
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 637 users

The Big Programming Thread - Page 672

Forum Index > General Forum
Post a Reply
Prev 1 670 671 672 673 674 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.
Khalum
Profile Joined September 2010
Austria831 Posts
October 28 2015 15:31 GMT
#13421
On October 29 2015 00:25 _Grazze_ wrote:
Yo dudes! I'm trying to program a change calcuator in Java for an assignment I have in school. It works kinda okay but it wont print out cents. Any ideas?

Code in spoiler.


Yo dude! This is not the place where people correct your homework!

That being said, think about the line where you convert your money from double to int.
Manit0u
Profile Blog Joined August 2004
Poland17243 Posts
October 28 2015 16:34 GMT
#13422
Also, why the hell are you even using doubles? Just do everything in cents (int) and convert it to different value only for printing purposes... Much easier and safer.
Time is precious. Waste it wisely.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2015-10-28 16:47:03
October 28 2015 16:46 GMT
#13423
--- Nuked ---
Manit0u
Profile Blog Joined August 2004
Poland17243 Posts
Last Edited: 2015-10-28 17:24:02
October 28 2015 17:23 GMT
#13424
On October 29 2015 01:46 Nesserev wrote:
Show nested quote +
On October 29 2015 01:34 Manit0u wrote:
Also, why the hell are you even using doubles? Just do everything in cents (int) and convert it to different value only for printing purposes... Much easier and safer.

I think the insight of doing everything in cents is something that comes with a certain notion of experience, even if its tiny. Would 'newb' Manit0u X years ago have tackled this problem by doing everything in cents from the get-go, even if someone hadn't shown it to him before? Would that really be your first idea? I don't know you... but I know that newb me would have done the same thing as him, and used doubles first.


That's why I suggested using cents instead of doubles. I also didn't know about that until I've discovered that Symfony framework introduced special form field type for this purpose. Examining how it worked was enlightening. Now I'm sharing the wisdom
Time is precious. Waste it wisely.
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
Last Edited: 2015-10-28 17:36:17
October 28 2015 17:32 GMT
#13425
Luckily I learned that doubles are an awful way to represent an amount of money long before I ever needed it. Too bad that we still use doubles for that at work anyways.

Ideally, you would have a Money class that bundles amount and currency. It can also provide common meney-related functionality and information like the appropriate formatting. For a small project that would be overkill, of course.
If you have a good reason to disagree with the above, please tell me. Thank you.
phantomfive
Profile Joined April 2010
Korea (South)404 Posts
October 28 2015 17:59 GMT
#13426
On October 29 2015 02:32 spinesheath wrote:
Luckily I learned that doubles are an awful way to represent an amount of money long before I ever needed it. Too bad that we still use doubles for that at work anyways.

I would never voluntarily use doubles for money, but if you are forced to do it:

you can get away with it, as long as you are careful when you do arithmetic.
Here is an example.
To ease another's heartache is to forget one's own - Lincoln
Itsmedudeman
Profile Blog Joined March 2011
United States19229 Posts
October 28 2015 18:43 GMT
#13427
A lot of textbook examples will just go ahead and use doubles for currency. The efficiency of the program itself isn't really their main concern I guess.
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
October 28 2015 18:49 GMT
#13428
On October 29 2015 02:59 phantomfive wrote:
Show nested quote +
On October 29 2015 02:32 spinesheath wrote:
Luckily I learned that doubles are an awful way to represent an amount of money long before I ever needed it. Too bad that we still use doubles for that at work anyways.

I would never voluntarily use doubles for money, but if you are forced to do it:

you can get away with it, as long as you are careful when you do arithmetic.
Here is an example.

It's no big deal in my case because we just display prices as a point of reference and then pass the order on to a different system. It's still kinda sad.
If you have a good reason to disagree with the above, please tell me. Thank you.
Ropid
Profile Joined March 2009
Germany3557 Posts
Last Edited: 2015-10-28 18:54:38
October 28 2015 18:54 GMT
#13429
On October 29 2015 03:43 Itsmedudeman wrote:
A lot of textbook examples will just go ahead and use doubles for currency. The efficiency of the program itself isn't really their main concern I guess.

It's about mistakes, not efficiency. For example this here:

0.1 + 0.2

That's not 0.3 with floats and doubles. Weird stuff like this happens:

> 0.1 + 0.2 == 0.3
False

> 0.1 + 0.2 < 0.3
False

> 0.1 + 0.2 > 0.3
True

You need to fix it like in phantomfive's example, use rounding to force results into two digits after the decimal point to make things work correctly.
"My goal is to replace my soul with coffee and become immortal."
supereddie
Profile Joined March 2011
Netherlands151 Posts
Last Edited: 2015-10-28 19:41:55
October 28 2015 19:39 GMT
#13430
Even if you round, the binary representation of fractions is still a problem. To avoid other problems, use a delta in comparisons.

double delta = 0.00001; // max deviation/fault tolerance
Math.Abs(0.3 - (0.1 + 0.2)) < delta
"Do not try to make difficult things possible, but make simple things simple." - David Platt on Software Design
Amnesty
Profile Joined April 2003
United States2054 Posts
October 29 2015 07:38 GMT
#13431
So awhile ago I found this math library (C++) that had a bunch of functions useful for screen animations and transitions and such.
For example, you can have menu button start by moving fast, but as it approaches where you would like it too land, it will slow way down.
Or, move slowly at first, make fast progress in the middle, and then slow down again (like a bell curve).
It was a pure math library, im just describing how i used it with graphics.

Anyway, the question is, do you know what keywords I should I should try to hopefully find it again?
I tried stuff like C++ timestep smoothing smoothstep, and various combinations but i don't really know what a collection of those formulas would be called.


The sky just is, and goes on and on; and we play all our BW games beneath it.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
October 30 2015 06:12 GMT
#13432
Hey y'all, I've got a design question. I'm trying to implement logging for my project in Python. We log normally, to a daily log file. Then, at the end of the day we switch to the log file for the next day. I'm planning on giving it a 10 second delay(to avoid problems with logged items right at midnight), then uploading the log file to our cloud storage, so we only have the log file for one day at a time.

However, I'm wondering what the best way to do this would be. My current idea is to have a "heartbeat" script on our server that starts when the server starts. It initiates a sched.enterabs, which will run a function at a specific time of day, 10 seconds after midnight. However, this has a few problems: if we start the server between midnight and 10 seconds after midnight, then we should have a problem with the day being off by one. Further, it's not threadsafe. If we are simply waiting for the event we've tied up a whole processor with that.

I'm thinking that I should use threading.timer. Then I can simply run the script on startup. It would then find the amount of time until the next time I want to upload the log, and wait that long. However, it then has a problem with running it per day. I'm not sure exactly how to deal with that problem.

Anyway, if anyone has suggestions on how to deal with this I'd appreciate them. Part of this has been rubber ducky programming for me to try to figure it out. Peace!
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
October 30 2015 07:40 GMT
#13433
On October 30 2015 15:12 WarSame wrote:
Hey y'all, I've got a design question. I'm trying to implement logging for my project in Python. We log normally, to a daily log file. Then, at the end of the day we switch to the log file for the next day. I'm planning on giving it a 10 second delay(to avoid problems with logged items right at midnight), then uploading the log file to our cloud storage, so we only have the log file for one day at a time.

However, I'm wondering what the best way to do this would be. My current idea is to have a "heartbeat" script on our server that starts when the server starts. It initiates a sched.enterabs, which will run a function at a specific time of day, 10 seconds after midnight. However, this has a few problems: if we start the server between midnight and 10 seconds after midnight, then we should have a problem with the day being off by one. Further, it's not threadsafe. If we are simply waiting for the event we've tied up a whole processor with that.

I'm thinking that I should use threading.timer. Then I can simply run the script on startup. It would then find the amount of time until the next time I want to upload the log, and wait that long. However, it then has a problem with running it per day. I'm not sure exactly how to deal with that problem.

Anyway, if anyone has suggestions on how to deal with this I'd appreciate them. Part of this has been rubber ducky programming for me to try to figure it out. Peace!


You might want to look into logrotate. It essentially does all of that already.

In your project you simply write to a file and at the time you specify, logrotate renames the old file and creates a replacement log file seamlessly and any script you start afterwards writes to the new file. It can also gzip older logs and does a bunch of other fancy things.
Manit0u
Profile Blog Joined August 2004
Poland17243 Posts
October 30 2015 18:54 GMT
#13434
On October 29 2015 04:39 supereddie wrote:
Even if you round, the binary representation of fractions is still a problem. To avoid other problems, use a delta in comparisons.

double delta = 0.00001; // max deviation/fault tolerance
Math.Abs(0.3 - (0.1 + 0.2)) < delta


All cool and dandy, but what do you want to compare here?

You have 2 doubles and you want to see if the result of an operation performed on them is within delta. How do you determine what do you want to compare the result against?

It's nice when talking about 0.1, 0.2 and 0.3 for the sake of examples, but what if you don't know any of them beforehand?
Time is precious. Waste it wisely.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
October 30 2015 19:25 GMT
#13435
Thanks! That led me on to looking at cron jobs, which I think is what I want. If I use cron to schedule it daily then I can run it in Python, which is necessary to deal with the files nicely I believe - they have to get uploaded to s3. Appreciate the help!
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
teamamerica
Profile Blog Joined July 2010
United States958 Posts
October 31 2015 02:21 GMT
#13436
On October 31 2015 04:25 WarSame wrote:
Thanks! That led me on to looking at cron jobs, which I think is what I want. If I use cron to schedule it daily then I can run it in Python, which is necessary to deal with the files nicely I believe - they have to get uploaded to s3. Appreciate the help!


If you're using python logging module there's rotating handler and or syslog handler depending on how you want to handle.

Even if you go the logrotate & cron job option, I'd advise using the logging module out to a normal file.
RIP GOMTV. RIP PROLEAGUE.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
October 31 2015 04:04 GMT
#13437
My current setup is to logout to a normal file for the day(so today would be "logfile-instanceName-2015-10-30.txt") with the python logging function(passed through a handler that I made). At the end of the day I plan to use cron which will run a script called rotateLogs.py. This accesses a function inside my main logging file, localLogging.py. The function is called rotateLogs() and it uploads the previous day's log, and then deletes it. Logging automatically switches to the new day's file because I determine the day of the file every time I try to log something(which is probably inefficient but our log traffic is very low). TimedRotatingFileHandler kinda looks like what I'm looking for, but I don't think can call a function on itself when its time is up.
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
phantomfive
Profile Joined April 2010
Korea (South)404 Posts
October 31 2015 06:05 GMT
#13438
On October 29 2015 16:38 Amnesty wrote:
So awhile ago I found this math library (C++) that had a bunch of functions useful for screen animations and transitions and such.
For example, you can have menu button start by moving fast, but as it approaches where you would like it too land, it will slow way down.
Or, move slowly at first, make fast progress in the middle, and then slow down again (like a bell curve).
It was a pure math library, im just describing how i used it with graphics.

Anyway, the question is, do you know what keywords I should I should try to hopefully find it again?
I tried stuff like C++ timestep smoothing smoothstep, and various combinations but i don't really know what a collection of those formulas would be called.

When I wrote a library with graphics like that, I used some Bezier curves. They were easy to implement with a speed and an acceleration.

The explanations of Bezier curves on the internet are a little dense, but once I got through that, the concepts are really simple.
To ease another's heartache is to forget one's own - Lincoln
Amnesty
Profile Joined April 2003
United States2054 Posts
October 31 2015 06:58 GMT
#13439
I remembered the name. The group of functions I was looking for are commonly referred to as easing functions.
The sky just is, and goes on and on; and we play all our BW games beneath it.
supereddie
Profile Joined March 2011
Netherlands151 Posts
October 31 2015 09:10 GMT
#13440
On October 31 2015 03:54 Manit0u wrote:
Show nested quote +
On October 29 2015 04:39 supereddie wrote:
Even if you round, the binary representation of fractions is still a problem. To avoid other problems, use a delta in comparisons.

double delta = 0.00001; // max deviation/fault tolerance
Math.Abs(0.3 - (0.1 + 0.2)) < delta


All cool and dandy, but what do you want to compare here?

You have 2 doubles and you want to see if the result of an operation performed on them is within delta. How do you determine what do you want to compare the result against?

It's nice when talking about 0.1, 0.2 and 0.3 for the sake of examples, but what if you don't know any of them beforehand?

The delta should be an application or business rule. The others can just be variables or something. Basically anywhere you do an equals comparison between floats/doubles you can replace it with this.

Useless example:

// Somewhere else
internal static readonly double FaultTolerance = 0.001;

private bool IsOneThird(double someNumber)
{
// any someNumer between 0.332 and 0.334 is counted as 1/3
return (Math.Abs(0.33 - someNumer) < Constants.FaultTolerance);
}
"Do not try to make difficult things possible, but make simple things simple." - David Platt on Software Design
Prev 1 670 671 672 673 674 1031 Next
Please log in or register to reply.
Live Events Refresh
RotterdaM Event
16:00
Rotti Stream Rumble 4k Edition
RotterdaM443
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 762
RotterdaM 443
Hui .357
MaxPax 334
StarCraft: Brood War
Bisu 1941
EffOrt 1308
Flash 1304
Jaedong 1180
Hyuk 821
Stork 371
actioN 369
Soulkey 276
Soma 275
Snow 187
[ Show more ]
firebathero 175
Mind 98
JulyZerg 71
TY 69
sSak 64
Barracks 57
Sharp 50
JYJ46
Terrorterran 45
PianO 43
Rock 31
HiyA 21
Aegong 20
soO 16
yabsab 15
GoRush 11
Shine 8
IntoTheRainbow 7
Dota 2
Gorgc6615
qojqva3321
League of Legends
singsing2289
Dendi1253
Counter-Strike
fl0m1143
markeloff176
Super Smash Bros
Mew2King204
Other Games
hiko1544
Beastyqt844
ceh9366
Lowko307
crisheroes263
ArmadaUGS149
KnowMe140
Trikslyr62
Organizations
Other Games
gamesdonequick47269
StarCraft 2
angryscii 21
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• Reevou 7
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Michael_bg 2
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Nemesis6915
• TFBlade833
• Jankos802
Other Games
• Shiphtur316
Upcoming Events
Replay Cast
7h 31m
Sparkling Tuna Cup
17h 31m
WardiTV European League
23h 31m
MaNa vs sebesdes
Mixu vs Fjant
ByuN vs HeRoMaRinE
ShoWTimE vs goblin
Gerald vs Babymarine
Krystianer vs YoungYakov
PiGosaur Monday
1d 7h
The PondCast
1d 17h
WardiTV European League
1d 19h
Jumy vs NightPhoenix
Percival vs Nicoract
ArT vs HiGhDrA
MaxPax vs Harstem
Scarlett vs Shameless
SKillous vs uThermal
uThermal 2v2 Circuit
1d 23h
Replay Cast
2 days
RSL Revival
2 days
ByuN vs SHIN
Clem vs Reynor
Replay Cast
3 days
[ Show More ]
RSL Revival
3 days
Classic vs Cure
FEL
3 days
RSL Revival
4 days
FEL
4 days
FEL
4 days
BSL20 Non-Korean Champi…
5 days
Bonyth vs QiaoGege
Dewalt vs Fengzi
Hawk vs Zhanhun
Sziky vs Mihu
Mihu vs QiaoGege
Zhanhun vs Sziky
Fengzi vs Hawk
Sparkling Tuna Cup
5 days
RSL Revival
5 days
FEL
5 days
BSL20 Non-Korean Champi…
6 days
Bonyth vs Dewalt
QiaoGege vs Dewalt
Hawk vs Bonyth
Sziky vs Fengzi
Mihu vs Zhanhun
QiaoGege vs Zhanhun
Fengzi vs Mihu
Liquipedia Results

Completed

BSL Season 20
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL 2v2 Season 3
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Jiahua Invitational
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
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
CCT Season 2 Global Finals
IEM Melbourne 2025

Upcoming

2025 ACS Season 2: Qualifier
CSLPRO Last Chance 2025
CSL Xiamen Invitational
2025 ACS Season 2
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
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.