• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 02:36
CEST 08:36
KST 15:36
  • 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
HomeStory 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 Energy6Code S RO8 Preview: herO, Zoun, Bunny, Classic7
Community News
Weekly Cups (June 23-29): Reynor in world title form?6FEL Cracov 2025 (July 27) - $8000 live event13Esports World Cup 2025 - Final Player Roster14Weekly Cups (June 16-22): Clem strikes back1Weekly Cups (June 9-15): herO doubles on GSL week4
StarCraft 2
General
StarCraft Mass Recall: SC1 campaigns on SC2 thread The SCII GOAT: A statistical Evaluation Weekly Cups (June 23-29): Reynor in world title form? How does the number of casters affect your enjoyment of esports? Esports World Cup 2025 - Final Player Roster
Tourneys
HomeStory Cup 27 (June 27-29) WardiTV Mondays SOOPer7s Showmatches 2025 FEL Cracov 2025 (July 27) - $8000 live event $200 Biweekly - StarCraft Evolution League #1
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers [G] Darkgrid Layout
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma Mutation # 477 Slow and Steady
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion StarCraft & BroodWar Campaign Speedrun Quest ASL20 Preliminary Maps Unit and Spell Similarities
Tourneys
[BSL20] GosuLeague RO16 - Tue & Wed 20:00+CET The Casual Games of the Week Thread [Megathread] Daily Proleagues [BSL20] ProLeague LB Final - Saturday 20:00 CET
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread 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
Effective Commercial Building Cost Assessment Tips Trading/Investing Thread US Politics Mega-thread Stop Killing Games - European Citizens Initiative Things Aren’t Peaceful in Palestine
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread Korean Music Discussion
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
from making sc maps to makin…
Husyelt
Blog #2
tankgirl
Game Sound vs. Music: The Im…
TrAiDoS
StarCraft improvement
iopq
Heero Yuy & the Tax…
KrillinFromwales
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 566 users

The Big Programming Thread - Page 611

Forum Index > General Forum
Post a Reply
Prev 1 609 610 611 612 613 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.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2015-04-08 23:46:57
April 08 2015 23:31 GMT
#12201
On April 09 2015 08:04 bardtown wrote:
At the moment I do a little bit of C++/Python programming and I think I have potential. I'm pretty good at understanding complicated structures etc, but I am aware that my programming is just functional and I don't really understand what is going on at a very fundamental level. That's pretty disconcerting for me. Even things that should be really basic, like pointers, I'm not comfortable with because I don't know how/why/when they are efficient. Does anybody have a book recommendation that builds up from technical fundamentals? Maybe a computer science textbook is what I need, but I'd prefer something a bit more readable. It doesn't need to be a comprehensive book, obviously I can research things in more detail, but it needs to give me a sense of structure.


Pointers are just what they really are... pointers to memory. So you don't have to copy or work with temporary objects, but reference them instead. That is why they're efficient. If you work with heap memory (one that you have to manually allocate and deallocate, you're not bound to a function/method scope), but pointers can work with stack and heap. Nowadays, C++ uses references instead because in general they're safer (as in they're assumed not to be null unlike pointers).

Good C++ books:

Beginner: C++ Primer
Advanced: More Effective C++ (1995), Effective C++ 3rd edition, Effective STL, also the new Effective C++ for C++11/14 (newest standard)

Edit: I'll give you an example of why pointers are efficient. Let's have a function such as this one:


void swap(int a, int b)
{
int temp = a;
a = b;
b = temp;
}


Two problems:

1. Parameters 'a' and 'b' are copied under the cover. They're not referenced, even if you pass variables.
2. Numbers are swapped, but because of the above (variables are copied), swap is lost once you get out of scope, that is, when you exit execution of the function.

Solution:


void swap(int* a, int* b)
{
int temp = *a;
*a = *b;
*b = temp;
}


You solve all the two problems above. No extra copies are created. And swap isn't lost after function is executed. But what if you say:

swap(NULL, NULL)
? Undefined behaviour.

So, you can achieve much better syntax with somewhat null safety:


void swap(int& a, int& b)
{
int temp = a;
a = b;
b = temp;
}
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
April 08 2015 23:36 GMT
#12202
Honestly I don't like books and prefer to do projects.

Choose something that sounds cool and figure out how to do it in pure C. Every time you finish and start a new project you'll learn a shitton of new stuff. Like implement linked lists in C using pointers, with push/pop methods. That should challenge your fundamentals hard.
There is no one like you in the universe.
bardtown
Profile Joined June 2011
England2313 Posts
Last Edited: 2015-04-09 00:06:14
April 08 2015 23:48 GMT
#12203
I think it is less the language that I have problems with and more the way in which languages in general relate to hardware, etc. Something like C++ Primer goes: here's how you define variables, here's how you create loops, then suddenly it is talking about things like you do above. Stack and heap? What is unsafe about null pointers? What is the difference between references and pointers? I'm definitely missing a lot of knowledge here because I just learnt things as and when I needed them for functional programming. I'm looking at Elements of Programming, but I think that is too advanced for where I am at right now. I may try Introduction to Computation and Programming With Python to start.

Thanks for the example. It does help clarify things for me in terms of usage but I'm still feeling the need for a bottom-up relearning of concepts. It's silly that I've got this far without really thinking at all about values/addresses.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2015-04-09 00:20:52
April 08 2015 23:58 GMT
#12204
On April 09 2015 08:48 bardtown wrote:
I think it is less the language that I have problems with and more the way in which languages in general relate to hardware, etc. Something like C++ Primer goes: here's how you define variables, here's how you create loops, then suddenly it is talking about things like you do above. Stack and heap? What is unsafe about null pointers? What is the difference between references and pointers? I'm definitely missing a lot of knowledge here because I just learnt things as and when I needed them for functional programming. I'm looking at Elements of Programming, but I think that is too advanced for where I am at right now. I may try Introduction to Computation and Programming With Python to start.


There are two kinds of memory (actually three if you include static, but forget that for now): heap and stack.
Stack is faster, but smaller, yet you should prefer it whenever you can. It's also subject to scope rules. Heap memory is dynamic, slower than stack, but it doesn't care if you exit a method. It remains, but you have to manually delete heap based objects in C++. You don't care about that in Java/C# though.

Further reading: http://stackoverflow.com/questions/5836309/stack-memory-vs-heap-memory

Null pointers are unsafe as they don't point to anything. Example:


int* test = NULL; // or nullptr in C++11


And if you use 'test' before you initialise it, you're in the world of undefined, incorrect behaviour. Anyway, a lot of your questions can be googled. I think Effective C++ answers some of your questions, too. C++ Primer should definitely explain all of what you're asking as far as I remember.

Edit: I think references are just like pointers under the cover, but they're just like 'aliases'. Another name for an existing object, thus you don't have to check for:

if (!object)

or
if (object == NULL)


Both checks are the same btw.

On April 09 2015 08:36 Blisse wrote:
Honestly I don't like books and prefer to do projects.

Choose something that sounds cool and figure out how to do it in pure C. Every time you finish and start a new project you'll learn a shitton of new stuff. Like implement linked lists in C using pointers, with push/pop methods. That should challenge your fundamentals hard.


You can't start building proper houses before you learn how to do it. You can certainly build one, more likely a bad one though. I think books are a good way to learn stuff without having years of experience. It's all about best practices. One certainly needs practice not just theory, too.
bardtown
Profile Joined June 2011
England2313 Posts
April 09 2015 00:48 GMT
#12205
Thanks again for explaining. I could find everything online but that is a piecemeal approach which could leave me missing information I didn't even know I needed, hence looking for a structured book. I know of all the books you are recommending, just worry that a) they're very long and dense and b) they often assume basic knowledge that I don't have. May get a few different ones out the library and see if any have the approach I'm after
Ropid
Profile Joined March 2009
Germany3557 Posts
April 09 2015 01:08 GMT
#12206
Perhaps see if you can find some sort of rough overview about what the CPU and its assembly language can actually do and how C translates into that. It could be illuminating to see what actually happens when a function in C gets called and when it returns, what the parameters and variables actually are, what happens when there's an "if" or "while".

I tried to find something short but failed, instead found this book here which seems to be good but explains too much, enough to be actually useful if you'd wanted to start learning x86 Assembly: http://www.drpaulcarter.com/pcasm/
"My goal is to replace my soul with coffee and become immortal."
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2015-04-09 02:17:58
April 09 2015 02:17 GMT
#12207
--- Nuked ---
Mr. Wiggles
Profile Blog Joined August 2010
Canada5894 Posts
April 09 2015 14:40 GMT
#12208
I'd second 'Computer Organization and Design'.

One of the books I've found quite valuable for learning was Silberschatz, Galvin, and Gagne's 'Operating System Concepts'.

I'm on my phone right now, so I can't give a blurb, but I'd say to check them out.
you gotta dance
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2015-04-12 11:17:36
April 12 2015 11:13 GMT
#12209
--- Nuked ---
Prillan
Profile Joined August 2011
Sweden350 Posts
April 12 2015 11:33 GMT
#12210
On April 12 2015 20:13 Nesserev wrote:
Hey guys,

I'm currently looking into scraping data from websites, and a little bit of front-end development; something that I've never actively done before, so I was wondering...

If you go to the following link, or almost any other hotel booking page on expedia.com, hotels.com, etc. a message pops up with 'X amount of persons are watching this page right now'. What would be the best way to extract this information ('X')?
http://www.expedia.com/Bruges-Center-Hotels-Hotel-Dukes-Palace.h1853344.Hotel-Information?chkin=12/04/2015&chkout=13/04/2015

EDIT: Now that I'm at it; does anyone recommend any books/online tutorials regarding web scraping?

First you have to figure out if the data is included in the HTML source or received as an external file. Clicking "View Source" and searching for the term yields, in this case, no results. So the data must be loaded from JS. Using Chrome's (or Opera's in my case) dev tools allows you to capture any files transmitted. By filtering for XHR I found this file:
Remote Address:23.54.3.53:80
Request URL:http://www.expedia.se/Hotels/Offers?[...]
Request Method:GET
Status Code:200 OK

Full link: + Show Spoiler +
Request URL:http://www.expedia.se/Hotels/Offers?action=getAndUpdateHotelProductActivity&hotelIds=1853344&durationForViews=1800000&durationForBookings=172800000


Then it's just a matter of extracting the data from JSON:

{
"ViewStatus":0,
"BookingStatus":0,
"HotelProductActivityList":
[
{
"ViewCount":8,
"BookingCount":22,
"HotelId":1853344,
"isValidViewCount":true,
"isValidBookingCount":true
}
]
}


This is usually the method I follow.

If it's in the source code, use a html parser or regex to extract the value (regex for small things, html for big).
If it's in a json file, find out a way to retrieve the file and then grab the value.
TheBB's sidekick, aligulac.com | "Reality is frequently inaccurate." - Douglas Adams
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
April 12 2015 11:39 GMT
#12211
--- Nuked ---
Manit0u
Profile Blog Joined August 2004
Poland17241 Posts
April 13 2015 11:47 GMT
#12212
On April 09 2015 08:31 darkness wrote:
Show nested quote +
On April 09 2015 08:04 bardtown wrote:
At the moment I do a little bit of C++/Python programming and I think I have potential. I'm pretty good at understanding complicated structures etc, but I am aware that my programming is just functional and I don't really understand what is going on at a very fundamental level. That's pretty disconcerting for me. Even things that should be really basic, like pointers, I'm not comfortable with because I don't know how/why/when they are efficient. Does anybody have a book recommendation that builds up from technical fundamentals? Maybe a computer science textbook is what I need, but I'd prefer something a bit more readable. It doesn't need to be a comprehensive book, obviously I can research things in more detail, but it needs to give me a sense of structure.


Pointers are just what they really are... pointers to memory. So you don't have to copy or work with temporary objects, but reference them instead. That is why they're efficient. If you work with heap memory (one that you have to manually allocate and deallocate, you're not bound to a function/method scope), but pointers can work with stack and heap. Nowadays, C++ uses references instead because in general they're safer (as in they're assumed not to be null unlike pointers).

Good C++ books:

Beginner: C++ Primer
Advanced: More Effective C++ (1995), Effective C++ 3rd edition, Effective STL, also the new Effective C++ for C++11/14 (newest standard)


For the fundamentals isn't it better to simply read K&R? It's short, easy to understand and should give anyone really good basic knowledge. I know it's C and not C++, but when speaking of the most basic stuff that's pretty much irrelevant.
Time is precious. Waste it wisely.
sabas123
Profile Blog Joined December 2010
Netherlands3122 Posts
Last Edited: 2015-04-13 13:04:17
April 13 2015 13:02 GMT
#12213
OOP in php is giving me such a fcking headacke

 
$clients //I make this an array in the constructor

//this will return an array with $somevalue in it
public function getClient(){
$this->clients[] = $somevalue;
return $this->clients;
}

//this returns an empty array, Ill call setClient somewhere first at then Ill call getClient

public function setClient($somevalue){
$this->clients[] = $somevalue;
}


public function getClient(){
return $this->clients;
}



ps this is just some write up code. but youll get the idea.
The harder it becomes, the more you should focus on the basics.
Manit0u
Profile Blog Joined August 2004
Poland17241 Posts
Last Edited: 2015-04-13 14:07:26
April 13 2015 13:55 GMT
#12214
On April 13 2015 22:02 sabas123 wrote:
OOP in php is giving me such a fcking headacke

 
$clients //I make this an array in the constructor

//this will return an array with $somevalue in it
public function getClient(){
$this->clients[] = $somevalue;
return $this->clients;
}

//this returns an empty array, Ill call setClient somewhere first at then Ill call getClient

public function setClient($somevalue){
$this->clients[] = $somevalue;
}


public function getClient(){
return $this->clients;
}



ps this is just some write up code. but youll get the idea.



class Client
{
protected $clients;

public function __construct()
{
$this->clients = array();
}

public function getClient()
{
$this->clients[] = $somevalue;

return $this->clients;
}
}

$clients = new Client;

print_r($clients->getClient());


Result:


Array
(
[0] =>
)



// var_dump instead of print_r

array(1) {
[0]=>
NULL
}


Despite pushing the uninitialized variable to the array everything works as intended.

What exactly was your problem?

Also, if you want full OOP you can always use ArrayObject instead of regular array
Time is precious. Waste it wisely.
Acrofales
Profile Joined August 2010
Spain17966 Posts
April 13 2015 13:59 GMT
#12215
On April 13 2015 22:02 sabas123 wrote:
OOP in php is giving me such a fcking headacke

 
$clients //I make this an array in the constructor

//this will return an array with $somevalue in it
public function getClient(){
$this->clients[] = $somevalue;
return $this->clients;
}

//this returns an empty array, Ill call setClient somewhere first at then Ill call getClient

public function setClient($somevalue){
$this->clients[] = $somevalue;
}


public function getClient(){
return $this->clients;
}



ps this is just some write up code. but youll get the idea.


What exactly is your problem with it? Other than your first method, which seems both superfluous and wrong: firstly, it is overwritten immediately by the second declaration of getClient() and secondly, $somevalue is not initialized in this bit of code, so presumably it is null, but you definitely don't want to add it to your client array.

Other than that first method, it seems like completely standard getter and setter code, so unless you have a problem in general with getters and setters (which I agree can be quite a tedious design pattern, but makes UPKEEP of the code much easier), what specifically is your problem with OOP in PHP?
sabas123
Profile Blog Joined December 2010
Netherlands3122 Posts
April 13 2015 14:15 GMT
#12216
$somevalue is a value that I will use some where else in the script

the problem is that I apperntly cant set the value or get the setted value back.
The harder it becomes, the more you should focus on the basics.
Manit0u
Profile Blog Joined August 2004
Poland17241 Posts
Last Edited: 2015-04-13 14:31:38
April 13 2015 14:29 GMT
#12217
What is the value?

How do you set it?

How do you get it?

It really looks like you're trying to create the most basic collection class. Those aren't hard at all...

http://www.sitepoint.com/collection-classes-in-php/
Time is precious. Waste it wisely.
sabas123
Profile Blog Joined December 2010
Netherlands3122 Posts
April 13 2015 14:32 GMT
#12218
On April 13 2015 23:29 Manit0u wrote:
What is the value?

How do you set it?

How do you get it?

I set it with

public function setClient($input){
$this->clients[$input];
}


and then I get it with


public function getClient(){
return $this->clients;
}


and the value is a string.
The harder it becomes, the more you should focus on the basics.
Acrofales
Profile Joined August 2010
Spain17966 Posts
Last Edited: 2015-04-13 18:26:41
April 13 2015 18:24 GMT
#12219
On April 13 2015 23:32 sabas123 wrote:
Show nested quote +
On April 13 2015 23:29 Manit0u wrote:
What is the value?

How do you set it?

How do you get it?

I set it with

public function setClient($input){
$this->clients[$input];
}


and then I get it with


public function getClient(){
return $this->clients;
}


and the value is a string.


$this->clients[$input] does not set anything... it gets the value at the array index $input. Been a while since I programmed php, but pretty sure this throws an error unless you have somehow initialized your array already and there is an actual value at index $input. In that case it will return that value, but your method does not return, so in the end it will simply do nothing.

Use

public function setClient($input){
$this->clients[]=$input;
}


To be completely correct, you should probably not call this setClient, but addClient. You should also call your getClient() method getClients(), because it is returning the list of clients as a whole, and not just one specific client. But the naming convention of your methods seems to be a smaller problem than the fact that your basic code is wrong.


EDIT: if what getClient() returns is a string, you are either initializing $this->clients wrong (as a string instead of an array), or you are casting it to a string somewhere along the line.
boon2537
Profile Blog Joined October 2010
United States905 Posts
April 13 2015 19:56 GMT
#12220
I chose to do a simple tic-tac-toe with an A.I. in Lisp as a project for my programming language class. Since I'm a noob with functional stuff, I just abuse progn make life easy for myself. I just hope my professor doesn't mind that too much >.<
Prev 1 609 610 611 612 613 1031 Next
Please log in or register to reply.
Live Events Refresh
Next event in 4h 24m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft410
mcanning 131
StarCraft: Brood War
Larva 655
TY 453
Snow 144
Noble 18
Hm[arnc] 6
Bale 5
Britney 0
Dota 2
febbydoto37
League of Legends
JimRising 641
Counter-Strike
summit1g7775
Stewie2K623
Other Games
shahzam1030
KnowMe144
NeuroSwarm54
Mew2King41
Organizations
Other Games
gamesdonequick832
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 12 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Rush1589
• Stunt544
Upcoming Events
Wardi Open
4h 24m
PiGosaur Monday
17h 24m
The PondCast
1d 3h
Replay Cast
1d 17h
RSL Revival
2 days
ByuN vs Classic
Clem vs Cham
WardiTV European League
2 days
Replay Cast
2 days
RSL Revival
3 days
herO vs SHIN
Reynor vs Cure
WardiTV European League
3 days
FEL
3 days
[ Show More ]
Korean StarCraft League
3 days
CranKy Ducklings
4 days
RSL Revival
4 days
FEL
4 days
Sparkling Tuna Cup
5 days
RSL Revival
5 days
FEL
5 days
BSL: ProLeague
5 days
Dewalt vs Bonyth
Replay Cast
6 days
Liquipedia Results

Completed

Proleague 2025-06-28
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL 2v2 Season 3
BSL Season 20
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
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
YaLLa Compass Qatar 2025

Upcoming

CSLPRO Last Chance 2025
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.