• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 02:37
CEST 08:37
KST 15:37
  • 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
[ASL22] Ro16 Preview: Holy Diver4[ASL22] Ro16 Preview: Rough Waters10[ASL22] Ro24 Preview: Siren's Call8[ASL22] Ro24 Preview: Summer's End9Serral wins HomeStory Cup 2915
Community News
StarCraft open world shooter announced at BlizzCon84Weekly Cups (Aug 30-Sep 7): herO thrives amid growing schism10Official StarCraft website teases new content ahead of BlizzCon?174Stellar Fest TWO the Moon (Dec 16-20)9Weekly Cups (August 24-30): Patches' balance mod takes over3
StarCraft 2
General
How do you feel about the StarCraft shooter announcement at BlizzCon 2026? StarCraft open world shooter announced at BlizzCon Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool Balance hotfix patch 5.0.16b (July 16) Team Liquid Map Contest #22: Results and Winners
Tourneys
RSL Revival: Season 6 - Qualifiers and Main Event SC2 AI Tournament 2026 Fall RSL goes to London! 2026 Offline Finals Nov 21-22 Sparkling Tuna Cup - Weekly Open Tournament KSL Week #92
Strategy
[G] Having the right mentality to improve
Custom Maps
Nexus Wars 2021 GUIDE [M] (2) Industrial Park
External Content
Mutation # 543 Enhanced Defenses The PondCast: SC2 News & Results Mutation # 542 The Ascended Mutation # 541 Binary Choice
Brood War
General
[D] Brainstorming a balance patch for Brood war [ASL22] Ro16 Preview: Holy Diver BGH Auto Balance -> http://bghmmr.eu/ Official StarCraft website teases new content ahead of BlizzCon? ASL22 General Discussion
Tourneys
[ASL22] Ro16 Group C [ASL22] Ro16 Group B [ASL22] Ro16 Group A Escore Tournament - Season 3
Strategy
Replay Review Process - What do you do? Simple Questions, Simple Answers Odyssey Mineral Stack Saturation Game Theory for Starcraft
Other Games
General Games
Diablo IV Nintendo Switch Thread EVE Corporation [Maplestory Hardcore] Let's Play~!! General RTS Discussion Thread
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
[TL LoL EUW IHs] Teemo shall perish
Heroes of the Storm
Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Community Thread
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread UK Politics Mega-thread Things Aren’t Peaceful in Palestine Trading/Investing Thread
Fan Clubs
MarineLorD Fan Club The Creator Fan Club The ShoWTimE Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Diablo Animated Series on Netflix
Sports
Football (Soccer) Thread TeamLiquid Health and Fitness Initiative For 2023 MLB/Baseball 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Northern Ireland Global Starcraft
Blogs
Virtual Romance, Real-Life C…
TrAiDoS
Regacy Esports:Our Goa…
regacyesports
Dreaming of BW patches (mod…
c3rberUs
LOCKPICKING NOOB
LUCKY_NOOB
Customize Sidebar...

Website Feedback

Closed Threads



Active: 6725 users

The Big Programming Thread - Page 611

Forum Index > General Forum
Post a Reply
Prev 1 609 610 611 612 613 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.
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
Poland17843 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
Poland17843 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
Spain18438 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
Poland17843 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
Spain18438 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 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 3h 23m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
NeuroSwarm 159
ProTech140
StarCraft: Brood War
GuemChi 1745
BeSt 432
Bale 84
Aegong 33
Noble 11
Icarus 7
League of Legends
JimRising 642
Other Games
summit1g15117
ceh9266
Mew2King46
Organizations
Other Games
gamesdonequick1085
[ Show 11 non-featured ]
StarCraft 2
• Berry_CruncH370
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• Migwel
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• lizZardDota2138
League of Legends
• Stunt408
Upcoming Events
Afreeca Starleague
3h 23m
Light vs JyJ
Soulkey vs hero
WardiTV Weekly
4h 23m
Monday Night Weeklies
9h 23m
Afreeca Starleague
1d 3h
Snow vs Shinee
Shine vs EffOrt
GSL
1d 4h
PiGosaur Cup
1d 17h
The PondCast
2 days
Kung Fu Cup
2 days
Replay Cast
2 days
KCM Race Survival
3 days
[ Show More ]
IntoTheTV X SOOP
3 days
Replay Cast
3 days
IntoTheTV X SOOP
4 days
Replay Cast
4 days
GSL
5 days
Replay Cast
5 days
GSL
6 days
Shopify Rebellion Sundays
6 days
Spirit vs Mixu
Replay Cast
6 days
Liquipedia Results

Completed

Blizzard Classic Cup 2026
Blizzard Classic Cup 2026
Big Dog Cup 2026 Div 1

Ongoing

KCM Race Survival 2026 Season 3
K-JUNGMAN
ASL Season 22
Super Anchor Qualifying S3
CSL 2026 AUTUMN (S22)
Acropolis #5
Calamity Invitational
FISSURE Playground #3
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
Stake Ranked Episode 3
XSE Pro League 2026

Upcoming

Acropolis #5 - GSA
Acropolis #5 - GSB
Acropolis #5 - GSC
SC4ALL II: Brood War
HSC XXX
Stellar Fest 2: Lunar Cup
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
RSL Offline Finals
PGL Major Singapore 2026
Stake Ranked Episode 6
BLAST Rivals Fall 2026
IEM Beijing 2026
Stake Ranked Episode 5
PGL Masters Bucharest 2026
1win Private Club #2
Thunderpick World Champ. '26
ESL Pro League Season 24
Stake Ranked Episode 4
1win Private Club #1
Logitech G Play Connect 2026
SL StarSeries Fall 2026
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.