• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 08:55
CET 14:55
KST 22:55
  • 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
TL.net Map Contest #21: Winners10Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13TL.net Map Contest #21: Voting12[ASL20] Ro4 Preview: Descent11
Community News
StarCraft, SC2, HotS, WC3, Returning to Blizzcon!33$5,000+ WardiTV 2025 Championship6[BSL21] RO32 Group Stage4Weekly Cups (Oct 26-Nov 2): Liquid, Clem, Solar win; LAN in Philly2Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win10
StarCraft 2
General
Mech is the composition that needs teleportation t TL.net Map Contest #21: Winners Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win RotterdaM "Serral is the GOAT, and it's not close" 5.0.15 Patch Balance Hotfix (2025-10-8)
Tourneys
Constellation Cup - Main Event - Stellar Fest $5,000+ WardiTV 2025 Championship Sparkling Tuna Cup - Weekly Open Tournament Merivale 8 Open - LAN - Stellar Fest Sea Duckling Open (Global, Bronze-Diamond)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection Mutation # 495 Rest In Peace
Brood War
General
[ASL20] Ask the mapmakers — Drop your questions BW General Discussion [BSL21] RO32 Group Stage BGH Auto Balance -> http://bghmmr.eu/ SnOw's ASL S20 Finals Review
Tourneys
[Megathread] Daily Proleagues [ASL20] Grand Finals [BSL21] RO32 Group B - Sunday 21:00 CET [BSL21] RO32 Group A - Saturday 21:00 CET
Strategy
Current Meta PvZ map balance How to stay on top of macro? Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Path of Exile Should offensive tower rushing be viable in RTS games? Dawn of War IV
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
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine YouTube Thread Dating: How's your luck?
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece Anime Discussion Thread Movie Discussion! Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Why we need SC3
Hildegard
Reality "theory" prov…
perfectspheres
Our Last Hope in th…
KrillinFromwales
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1412 users

The Big Programming Thread - Page 841

Forum Index > General Forum
Post a Reply
Prev 1 839 840 841 842 843 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.
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
February 10 2017 08:38 GMT
#16801
On February 10 2017 12:18 WarSame wrote:
What is an elegant way to set a bunch of div colours in SASS?

I would ideally like to do something like
$brown: #955436
$lightblue: #AAE0FA
$pink: #D93A96
$orange: #F7941D
$red: #ED1B24
$yellow: #FEF224
$green: #1FB25A
$darkblue: #0072BB

.block-(colorexample)
background-color:$colorexample


where I could have divs with classes like
block-brown
and have it automatically sub in the colour. Should I just not bother and make a block-colour for every single colour I have?


Please don't.

Name your CSS classes after what they represent, not after what they look like. Otherwise you'll either have to search and replace all the instances when your Boss tells you that all brown buttons should now be green, which negates all the advantages of CSS, or you have a class "brown" that is now green.
Artesimo
Profile Joined February 2015
Germany563 Posts
Last Edited: 2017-02-10 08:42:40
February 10 2017 08:38 GMT
#16802
Last questions:

About JOIN, if I got a ManyToMany Relationshipt between say, Students and lecturers:


ListL result em.createQuery("SELECT s, l FROM Studens s join s.lectures")
for(Iterator i = resultL.iterator(); i.hasNext();)
{
Object [] element = (Object[]) i.hasNext()//each Object[] containing a Student at [0] and a lecture at[1]
//using get-Methods to get Student/Lecture Name and printing it out


My Output would be equivalent to the joinedtable, where for every Student, all lectures get Listet:

_Student_ _Lecture_
Hans Lecture 1
Hans Lecture 2
Hans Lecture 3
Max Lecture 2
Max Lecture 3
Anna Lecture 3
. .
. .
. .
. .
Correct?

I could also acess the name of the Students directly, via using "SELECT s.name, l.name" instead.

An implicit join would also work like:

Select s, l,
FROM Student s, lesson l


Or to only get Name+all courses of one Students:

Select s, l,
FROM Student s, lesson l
WHERE s.name = "Hans"



Last question regarding general understanding:
All Querys in the end will be translated into SQL and send to the Database, this happens either after commiting an transaktion or calling flush() (which can be dangerous since it leaves the transaktionscope open, If the transaction fails afterwards, changes made before flush() are still in the database unless handled properly). However, how do you acess objekts then, that arent in the persitence context, but in the DB.

EntityManager em = emf.createEntityManager();//Session created
EntityTransaction tx = null;
try{
tx = em.getTransaction(); //transaction context created
tx.begin() //start transaciton();
// Customer001 previously not in persistence context/Cache
customer myCustomer = em.find(Customer.class, 001);//Now in persistence context
/*
Interaction with the object I pulled from the database - How can this work,
if the select-statement only get send after the commit?
Or get everything that you need for the tx get pulled from the DB before/em.find()
circumvents the commit? What about Entities pulled with JPQL-Querys?
*/
String name = myCustomer.getName()//
myCustomer.setName = "MC";

tx.commit();//End of transaction, transactions get send to DB
}catch (RuntimeException e){
if(tx != null) && tx.isActive()) tx.rollback();//Rollback transaction in case something went wrong, and tx got created
throw e;}
finally{em.close();} //closing the session
Manit0u
Profile Blog Joined August 2004
Poland17421 Posts
February 10 2017 09:49 GMT
#16803
Just fetch the objects you need before starting the transaction. You should really only use transactions for insert/update statements, not fetching.
Time is precious. Waste it wisely.
Artesimo
Profile Joined February 2015
Germany563 Posts
February 10 2017 09:59 GMT
#16804
On February 10 2017 18:49 Manit0u wrote:
Just fetch the objects you need before starting the transaction. You should really only use transactions for insert/update statements, not fetching.


So it doesn't work, or it is just really clunky? In case of it working, is my assumption correct, that fetching always happens immediately and only inserts/update/delete statements get hold back until .commit() is called?
Hanh
Profile Joined June 2016
146 Posts
February 10 2017 10:20 GMT
#16805
On February 10 2017 18:49 Manit0u wrote:
Just fetch the objects you need before starting the transaction. You should really only use transactions for insert/update statements, not fetching.


Not true if you care about isolation and atomicity. It can lead to serious issues specially in financial applications.
Manit0u
Profile Blog Joined August 2004
Poland17421 Posts
February 10 2017 10:57 GMT
#16806
On February 10 2017 19:20 Hanh wrote:
Show nested quote +
On February 10 2017 18:49 Manit0u wrote:
Just fetch the objects you need before starting the transaction. You should really only use transactions for insert/update statements, not fetching.


Not true if you care about isolation and atomicity. It can lead to serious issues specially in financial applications.


It really depends on what you need and what you're working with. Also, different SQL servers handle transactions differently (MS SQL for example will not allow for any other queries - even reads - until the transaction is commited and closed). Sure, if data integrity is critical, you want to wrap everything in transactions (and possibly add other mechanisms of ensuring that) but for the majority of use cases you won't need that level of paranoia.
Time is precious. Waste it wisely.
Hanh
Profile Joined June 2016
146 Posts
February 10 2017 11:09 GMT
#16807
This isn't paranoia. It is about a program behaving correctly or not. Saying that I don't need to do a transaction because I am only reading is the same as saying that I don't need to use a lock because I'm reading data (except that you won't crash because the database is always acquiring integrity locks). In some cases it is fine because there is an implicit transaction or auto commit in place. Yet if someone is learning about transactions, he should do the right thing.
Artesimo
Profile Joined February 2015
Germany563 Posts
Last Edited: 2017-02-10 11:34:36
February 10 2017 11:31 GMT
#16808
But I still struggle with the fact that the DB gets the data on commit, while I use fetches inside the transaction without having commited first. Does fetch always immediately get passed on to the DB and only write/delete/inserts/everything that manipulates data get send only on commit?
(In other words, persistence context stuff like adding/changing/removing data in/from it gets applied immediately, the Database only gets changed on commit. Fetching inside a transaction doesnt change anything on the DB but loads aditional entities in the persistence context? On commit, the persistence context will be synchronized with the DB)
Hanh
Profile Joined June 2016
146 Posts
February 10 2017 12:09 GMT
#16809
I don't know what the JPA (?) layer does but speaking from the database point of view, your transaction delimits a unit of execution that is Atomic and Isolated (A and I of ACID). Atomicity means that: Everything succeeds or everything fails. For instance, if you do 2 inserts and the 2nd one fails because of a constraint violation both inserts roll back. It doesn't mean that these inserts are sent at the end of the transaction. If you fetch something, then update it, and fetch again, your second fetch will return the updated value - even if the transaction isn't committed.
Isolation is more complicated but ideally, while your transaction is underway you don't see the actions of other transactions that are run concurrently. There are subtleties because isolation impacts performance and database implementations typically offer several options of isolation level.
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
February 11 2017 03:36 GMT
#16810
On February 10 2017 17:38 Morfildur wrote:
Show nested quote +
On February 10 2017 12:18 WarSame wrote:
What is an elegant way to set a bunch of div colours in SASS?

I would ideally like to do something like
$brown: #955436
$lightblue: #AAE0FA
$pink: #D93A96
$orange: #F7941D
$red: #ED1B24
$yellow: #FEF224
$green: #1FB25A
$darkblue: #0072BB

.block-(colorexample)
background-color:$colorexample


where I could have divs with classes like
block-brown
and have it automatically sub in the colour. Should I just not bother and make a block-colour for every single colour I have?


Please don't.

Name your CSS classes after what they represent, not after what they look like. Otherwise you'll either have to search and replace all the instances when your Boss tells you that all brown buttons should now be green, which negates all the advantages of CSS, or you have a class "brown" that is now green.

In this case they are going to be blocks to build a monopoly board, though, so they need to be named by colour.
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
berated-
Profile Blog Joined February 2007
United States1134 Posts
Last Edited: 2017-02-11 12:48:27
February 11 2017 12:46 GMT
#16811
On February 10 2017 20:31 Artesimo wrote:
But I still struggle with the fact that the DB gets the data on commit, while I use fetches inside the transaction without having commited first. Does fetch always immediately get passed on to the DB and only write/delete/inserts/everything that manipulates data get send only on commit?
(In other words, persistence context stuff like adding/changing/removing data in/from it gets applied immediately, the Database only gets changed on commit. Fetching inside a transaction doesnt change anything on the DB but loads aditional entities in the persistence context? On commit, the persistence context will be synchronized with the DB)


The DB definitely does not only get the data on commit. JPA is just built on top of JDBC, which gets a connection and starts a transaction if you are using your transaction manager. As others have tried to explain, and probably better than I will, you are actively participating in a database transaction at that time.

If you are trying to look at the database while your code has a transaction going on, you won't be able to see it -- that's the part of the isolation levels etc. It might feel like everything happens on commit, but, that's just when everything is actually committed, not when it is transferred.

If you are in the scope of a transaction, you can read the changes that you have made but others can't (most of the time).

Here is some reading on JDBC Transactions

Underneath the hood, when you start the transaction, it takes the connection that you have and turns off auto commit. Then every time you run something with JPA, it takes the jdbc connection and prepares a statement and then executes it -- all of that is done until you call commit.


Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
February 11 2017 19:57 GMT
#16812
So, C question.

I want to create a program that takes in input of the total number of variables that will have to be put into an array

then create an array that has size based on that input

but im reading that arrays can't be created with a variable as the size
wtf is that about, that seems really annoying
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
Last Edited: 2017-02-11 20:24:02
February 11 2017 20:20 GMT
#16813
On February 12 2017 04:57 travis wrote:
So, C question.

I want to create a program that takes in input of the total number of variables that will have to be put into an array

then create an array that has size based on that input

but im reading that arrays can't be created with a variable as the size
wtf is that about, that seems really annoying


Are you compiling C89 standard or C99 standard? The rules are different for each. The short answer is that the compiler wants to know exactly how much memory will be needed on the stack for your array.

The simple solution is to allocate on the heap using malloc, but that might not be what your class wants you to do.
I'll always be your shadow and veil your eyes from states of ain soph aur.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
February 11 2017 20:29 GMT
#16814
I think they want me to just initialize each array to size 50, because they told us in specifications that they won't need to hold more than 50 elements

but I don't like the huge lack in knowledge that comes with that hehe

I am finding I am not a big fan of C.... too much stuff that takes too long to do
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2017-02-11 21:41:13
February 11 2017 21:17 GMT
#16815
--- Nuked ---
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
Last Edited: 2017-02-11 21:22:04
February 11 2017 21:18 GMT
#16816
On February 12 2017 05:29 travis wrote:
I think they want me to just initialize each array to size 50, because they told us in specifications that they won't need to hold more than 50 elements

but I don't like the huge lack in knowledge that comes with that hehe

I am finding I am not a big fan of C.... too much stuff that takes too long to do


If you know the max size will be 50 its as simple as:
const int MAX_SIZE = 50;


When you compile your code the compiler knows that the arrays size is 50. It knows exactly how much stack space to allocate and it is happy.

extern int MAX_SIZE;


Contrast with the above where you're getting the max size from somewhere else. The compiler doesn't know what the value will be and it won't let you compile.
I'll always be your shadow and veil your eyes from states of ain soph aur.
Biolunar
Profile Joined February 2012
Germany224 Posts
February 11 2017 21:41 GMT
#16817
If you do this:
const int MAX_SIZE = 50;
T arr[MAX_SIZE];

then arr is a VLA. Don't use VLAs.
What is best? To crush the Zerg, see them driven before you, and hear the lamentations of the Protoss.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
February 11 2017 21:50 GMT
#16818
what about #define ARRAY_LENGTH 50 ?
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2017-02-11 22:14:55
February 11 2017 22:03 GMT
#16819
--- Nuked ---
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
February 11 2017 22:24 GMT
#16820
I was under the impression that a constant didn't change value, but when I wrote C89 was the worst months of my life so I'll just refrain from answering anymore about it since apparently I don't remember anything.
I'll always be your shadow and veil your eyes from states of ain soph aur.
Prev 1 839 840 841 842 843 1032 Next
Please log in or register to reply.
Live Events Refresh
CranKy Ducklings
10:00
Sea Duckling Open #140
CranKy Ducklings84
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RotterdaM 198
Railgan 42
Creator 14
StarCraft: Brood War
Sea 6694
Horang2 4040
GuemChi 1668
Jaedong 862
actioN 292
Mini 259
BeSt 247
Killer 230
Soma 220
EffOrt 210
[ Show more ]
Rush 169
Mind 92
Hyun 87
Bonyth 72
ToSsGirL 69
Backho 61
sas.Sziky 33
JYJ28
PianO 27
zelot 24
Aegong 14
soO 12
Terrorterran 10
Sacsri 9
sorry 9
HiyA 8
Dota 2
Gorgc6041
singsing2292
qojqva1772
Dendi596
XcaliburYe214
BananaSlamJamma90
Heroes of the Storm
Khaldor209
Other Games
B2W.Neo1194
Sick244
Lowko237
Fuzer 197
Hui .121
XaKoH 81
nookyyy 54
MindelVK19
Organizations
StarCraft 2
WardiTV622
Counter-Strike
PGL242
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• StrangeGG 67
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 2050
League of Legends
• Stunt689
• HappyZerGling113
Upcoming Events
IPSL
4h 5m
dxtr13 vs OldBoy
Napoleon vs Doodle
LAN Event
4h 5m
Lambo vs Clem
Scarlett vs TriGGeR
ByuN vs TBD
Zoun vs TBD
BSL 21
6h 5m
Gosudark vs Kyrie
Gypsy vs OyAji
UltrA vs Radley
Dandy vs Ptak
Replay Cast
9h 5m
Sparkling Tuna Cup
20h 5m
WardiTV Korean Royale
22h 5m
LAN Event
1d 1h
IPSL
1d 4h
JDConan vs WIZARD
WolFix vs Cross
BSL 21
1d 6h
spx vs rasowy
HBO vs KameZerg
Cross vs Razz
dxtr13 vs ZZZero
Replay Cast
1d 19h
[ Show More ]
Wardi Open
1d 22h
WardiTV Korean Royale
2 days
Replay Cast
3 days
Kung Fu Cup
3 days
Classic vs Solar
herO vs Cure
Reynor vs GuMiho
ByuN vs ShoWTimE
Tenacious Turtle Tussle
4 days
The PondCast
4 days
RSL Revival
4 days
Solar vs Zoun
MaxPax vs Bunny
Kung Fu Cup
4 days
WardiTV Korean Royale
4 days
RSL Revival
5 days
Classic vs Creator
Cure vs TriGGeR
Kung Fu Cup
5 days
CranKy Ducklings
6 days
RSL Revival
6 days
herO vs Gerald
ByuN vs SHIN
Kung Fu Cup
6 days
Liquipedia Results

Completed

BSL 21 Points
SC4ALL: StarCraft II
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
Stellar Fest: Constellation Cup
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual

Upcoming

SLON Tour Season 2
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
META Madness #9
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
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.